Command Cooldowns
Commands should have a cooldown to reduce the number of times a user uses a command to prevent an issue called "Spamming".
How does cooldowns
work?
cooldowns
work?cooldowns
is an Object
option that has 4 types of command cooldowns: perUser
, perGuild
, perUserPerGuild
and global
. These types of cooldowns help control servers that use a command and prevent abusing it which may crash the bot.
Let's use the "ping" command to demonstrate this:
What does these types of cooldowns help in?
Here is a table and a specific description on how cooldown types work:
perUser
Sets a cooldown for each user, even if they are in another server or not
perGuild
Sets a cooldown for each server. When a user runs a command in a server, other users will be affected when running that command. However, other servers will not be affected.
perUserPerGuild
Sets a cooldown for each user. Other users will not be affected. However, the user can still run that command in another server.
global
Sets a whole cooldown for all users when a user runs this command. This means that even if other users are not in the same server, the cooldown will still affect them.
When specifying cooldowns, please only specify one of them. Multiple cooldowns detected will result in a NoCliCommandError
.
Also, bot developers should have the freedom to manage cooldowns the way they want. This is useful when you want to slow down the usage of a command by a user. This is why updateCooldown()
and cancelCooldown()
options are implemented into ICommand.callback()
updateCooldown()
and cancelCooldown()
functions
updateCooldown()
and cancelCooldown()
functionsupdateCooldown()
updates the time the cooldown ends for the user while cancelCooldown()
cancels the whole cooldown for the user.
updateCooldown()
and cancelCooldown()
functions can only be used when a command is executed.
Last updated