在 discord.py 中重置命令的冷却时间

时间:2021-01-20 15:45:15

标签: python pycharm discord

我一直试图弄清楚 discord.py 或 python 中是否有一些东西会在命令返回时重置命令的冷却时间。例如(如下所示)有人输入 !math,但如果有另一个命令正在运行,该命令将不会继续执行,用户必须再次等待 60 秒,因为该命令正在冷却中。

代码举例:

@bot.command()
@commands.cooldown(1, 60.00, commands.BucketType.guild)
async def math(msg):
    if msg.channel.id != channel:
        return
    if another_command_running:
        await msg.send(msg.author.mention + " Another command is running")
        return
    ....
    ....
    ....

1 个答案:

答案 0 :(得分:0)

可以使用 Discord 的内置功能重置冷却时间:reset_cooldown,在您的情况下,它将重置数学命令冷却时间,以便用户能够立即再次使用它。

只需将 附加到命令应该移除冷却时间的位置。

math.reset_cooldown(ctx)