繁体   English   中英

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

[英]Reseting a cooldown of a command in discord.py

我一直试图弄清楚 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
    ....
    ....
    ....

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

只需 append 到命令应该删除冷却时间的地步。

math.reset_cooldown(ctx)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM