Cooldown For Command On Discord Bot Python

Solution 1:

You should decorate your command with

@commands.cooldown(1, 30, commands.BucketType.user)

This will add a ratelimit of 1 use per 30 seconds per user. docs, example

You can change the BucketType to default, channel or server to create a global, channel or server ratelimit instead, but you can only have 1 cooldown on a command.

Note: In discord.py rewrite (v1.0+) instead of BucketType.server, you have to use BucketType.guild.

This will also cause a CommandOnCooldown exception in on_command_error

Solution 2:

I know a method of sending in the channel that cooldown is in process.

@command_name.error
    async def command_name_error(ctx, error):
        if isinstance(error, commands.CommandOnCooldown):
            em = discord.Embed(title=f"Slow it down bro!",description=f"Try again in {error.retry_after:.2f}s.", color=color_code_here)
            await ctx.send(embed=em)

make sure you have imported bucket type. If not -

from discord.ext.commands import cooldown, BucketType

NOTE - Make sure the command cooldown event always has a different name and has to be the_command_name_here.error (don't make it the_command_name_here , insert the ACTUAL command name there.)