[英]Command Cooldown - discord.py
so I did a bit of research on how to make a feature like this and this is what I came up with:所以我对如何制作这样的功能做了一些研究,这就是我想出的:
@bot.command()
@commands.cooldown(1, 30, commands.BucketType.user)
async def test(ctx):
try:
await ctx.send("Success")
except commands.errors.CommandOnCooldown:
await ctx.send("This command is on cooldown")
What is the best way to make the bot send something like this: "You are on cooldown, try again in 26s"?让机器人发送这样的信息的最佳方法是什么:“你正在冷却,26 秒后再试”? I attempted to do this in the line
except commands.errors.CommandOnCooldown:
but this does not work.我试图在
except commands.errors.CommandOnCooldown:
的行中执行此except commands.errors.CommandOnCooldown:
但这不起作用。
Any help greatly appreciated非常感谢任何帮助
You can handle the error using Command.error()
您可以使用
Command.error()
处理错误
@bot.command()
@commands.cooldown(1, 30, commands.BucketType.user)
async def test(ctx):
await ctx.send("Success")
@test.error
async def test_error(ctx, error):
if isinstance(error, commands.CommandOnCooldown):
await ctx.send(error)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.