Skip to content

Instantly share code, notes, and snippets.

@15696
Created October 17, 2020 20:57
Show Gist options
  • Save 15696/98ea4724593cd769650f4190a7200e2f to your computer and use it in GitHub Desktop.
Save 15696/98ea4724593cd769650f4190a7200e2f to your computer and use it in GitHub Desktop.
simple cooldowns and cooldown handlers in discord.py
@client.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandOnCooldown):
await ctx.send(f"{round(error.retry_after, 2)} seconds left")
@client.command()
@commands.cooldown(1, 5, commands.BucketType.user)
async def command(ctx):
await ctx.send("command output")
# note that commands.cooldown is not really meant for cooldowns over an hour
# and restarting your bot will mess up all the cooldowns currently in place
# 1, 5, BucketType.user means individual users can use this command 1 time every 5 seconds
# check the api reference for more types of buckettypes:
# https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.discord.ext.commands.BucketType
@koer2fine
Copy link

thx mate

thx

gonna use this as well! wink

nice lol

my shd be saying cooldown is not callable

@mudkipdev
Copy link

Hello @koer2fine, this gist is extremely outdated. I would recommend you not use this as this was made 3 years ago.

@GustavoSchip
Copy link

Hello @koer2fine, this gist is extremely outdated. I would recommend you not use this as this was made 3 years ago.

@koer2fine
it is, but the idea is the same, you should get the latest knowledge from the docs of your preferred module!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment