gpt4 book ai didi

discord.py - 如何从错误功能重置命令冷却时间

转载 作者:行者123 更新时间:2023-12-04 08:04:50 25 4
gpt4 key购买 nike

我有个问题。似乎我不知道如何重置命令冷却时间,而不是在实际命令本身中。

@bot.command()
@commands.cooldown(1,900,type=commands.BucketType.member)
async def rob(ctx, left: discord.Member):
guild=ctx.author.guild
server_members=guild.members
if left in server_members:
print('found user')
random_chance = random.randint(0,1)
if random_chance == 1:
print('robbery successful')
else:
await ctx.channel.send('Robbery not successful lol noob')
else:
await ctx.channel.send('That person is not in this server... :sob:')

@rob.error
async def roberror(ctx, error):
if isinstance(error, commands.MissingRequiredArgument):
await ctx.channel.send('You have to supply me with someone to rob.. noob')
elif isinstance(error, commands.BadArgument):
await ctx.channel.send('You have to provide me with a valid person..')
elif isinstance(error, commands.CommandOnCooldown):
await ctx.channel.send(f'Chill. Your on cooldown. Try again in {math.ceil(error.retry_after)} seconds')
else:
raise error``` I would like to have it reset the command cooldown in the roberror function. Can anyone help me with this?

最佳答案

命令的冷却时间可以用 reset_cooldown 重置属性,然后将命令上下文作为参数传递。这是一个使用它的例子,rob是命令标识符然后 reset_cooldown是属性。此示例将重置命令的冷却时间

rob.reset_cooldown(ctx)
当“rob”命令不成功时,您似乎想放置它,您可以像这样添加它:
else:
await ctx.channel.send('Robbery not successful lol noob')
rob.reset_cooldown(ctx)
您可以在文档中找到更多信息: https://discordpy.readthedocs.io/en/latest/ext/commands/api.html

关于discord.py - 如何从错误功能重置命令冷却时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66270643/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com