cap
cap

Reputation: 125

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"? I attempted to do this in the line except commands.errors.CommandOnCooldown: but this does not work.

Any help greatly appreciated

Upvotes: 0

Views: 612

Answers (1)

Jawad
Jawad

Reputation: 2041

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)

Upvotes: 1

Related Questions