I wanted to set a cooldown for my bot in discord.py, I tried to do this with time.sleep(30)
, but it didn't work because it stops the full bot, but I need that you can do other commands in the time. Please in content.split and not discord ext. Can someone help me?
3 Answers
What you want is to use a decorator on your command.
The decorator for a cooldown is @commands.cooldown
@bot.command()
@commands.cooldown(x, y, commands.BucketType.z)
#your code here
...
x is how many times a command can be used in a given timeframe
y is that timeframe (in seconds)
z is who this applies to (a user, a channel, a server, or even global(default))
So: ...cooldown(2, 10, commands.BucketType.user)
will allow every user to use the command 2 times within 10 seconds.
Good luck!
You can read up on it here: Discord.py commands.cooldown
As a sidenote: time.sleep()
is something you can use to "pause" the bot within a command
print("hi")
time.sleep(30)
print("there")
This will put a delay between the two messages, instead of having them be printed immediately, one after the other. You should test this out in!

- 997
- 2
- 6
- 13
You can use asyncio.sleep()
for waiting inside the function, ex. inside on_ready()
event or @commands.cooldown
decorator (designed only for commands):
asyncio.sleep()
import asyncio
asyncio.sleep(seconds)
Asyncio.sleep
works like time.sleep
, but it doesn't block the entire code. It stops only one event. You can read more about the difference between time.sleep
and asyncio.sleep
here.
@commands.cooldown()
@client.command()
@commands.cooldown(rate, per, type)
async def example(ctx):
...
- rate - The number of times a command can be used before triggering a cooldown.
- per - The number of seconds to wait for a cooldown when it’s been triggered.
- type - The type of cooldown (cooldown that blocks only one user would be
commands.BucketType.user
. Check all types and choose one that suits your needs.

- 2,595
- 11
- 13
- 26
this is because time.sleep is blocking, you can use
@commands.cooldown(1, 5, commands.BucketType.user)

- 41
- 5