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?
Asked
Active
Viewed 148 times
-2
3 Answers
1
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!
![](../../users/profiles/14196628.webp)
AbdurJ
- 780
- 2
- 2
- 13
0
this is because time.sleep is blocking, you can use
@commands.cooldown(1, 5, commands.BucketType.user)
![](../../users/profiles/12956273.webp)
DankDumpster
- 41
- 4