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"? I attempted to do this in the line except commands.errors.CommandOnCooldown:
but this does not work.
Any help greatly appreciated
You can handle the error using 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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.