我正在使用具有以下命令的基于Python的Discord机器人
@client.command(name="Mine",
description="Mine daily.",
brief="Mine daily.",
aliases=['mine', 'm'],
pass_context=True)
@commands.cooldown(1, 30, commands.BucketType.user)
async def mine(ctx, arg):
<content>
但是,当用户达到命令的30秒速率限制时,它将错误输出到python shell
Ignoring exception in command Mine
Traceback (most recent call last):
File "C:\Users\raner\AppData\Local\Programs\Python\Python36\lib\site-
packages\discord\ext\commands\bot.py", line 846, in process_commands
yield from command.invoke(ctx)
File "C:\Users\raner\AppData\Local\Programs\Python\Python36\lib\site-
packages\discord\ext\commands\core.py", line 367, in invoke
yield from self.prepare(ctx)
File "C:\Users\raner\AppData\Local\Programs\Python\Python36\lib\site-
packages\discord\ext\commands\core.py", line 351, in prepare
raise CommandOnCooldown(bucket, retry_after)
discord.ext.commands.errors.CommandOnCooldown: You are on cooldown. Try
again in 28.58s
[我想要做的是得到一些剩余的冷却时间,然后将其放入可以在不和谐的情况下告诉用户的内容,例如'此命令受速率限制,请在28.58秒后重试'
我在网上找不到很多帮助,其中大多数已经过时或似乎无法使用。
谢谢!
您需要为处理error handler错误并发送消息的命令编写CommandOnCooldown
。
CommandOnCooldown