Skip to content Skip to sidebar Skip to footer

Catching Commandoncooldown Error

I am making a discord bot that has a cooldown and I am attempting to make an event that when the CommandOnCooldown Error occurs, the bot will DM them how much longer they have to w

Solution 1:

This is the general format for catching exceptions when using discord.py:

from discord.ext import commands

bot = commands.Bot('$')

@bot.eventasyncdefon_command_error(ctx, error):
    ifisinstance(error, commands.CommandOnCooldown):
        await ctx.send('This command is on a %.2fs cooldown' % error.retry_after)
    raise error  # re-raise the error so all the errors will still show up in console@commands.cooldown(1, 30)@bot.command()asyncdefgetalt(ctx):
    await ctx.send('in getalt')

bot.run('token')

The getalt is the command, which has a 30-second cooldown, is caught by the on_command_error event, in turns will send a message to the channel. If you have anything else that you’re unclear about, please refer to the detailed documentation here.

Post a Comment for "Catching Commandoncooldown Error"