我正在開發一個基于 python 的 discord bot,它具有以下命令@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 shellIgnoring exception in command MineTraceback (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 秒后重試”我在網上找不到太多幫助,而且大部分已經過時或似乎不起作用。
1 回答

ITMISS
TA貢獻1871條經驗 獲得超8個贊
您需要為您的命令編寫一個錯誤處理程序來處理CommandOnCooldown錯誤并發送消息。
@mine.error
async def mine_error(ctx, error):
if isinstance(error, commands.CommandOnCooldown):
msg = 'This command is ratelimited, please try again in {:.2f}s'.format(error.retry_after)
await ctx.send(msg)
else:
raise error
添加回答
舉報
0/150
提交
取消