I am trying to make a cooldown from my commands (The cooldown change depending on the command)
I have been struggling trying to find a way but I have found none . I would appreciate if someone could help.
The trivial thing to do is insert a timeout into every command.
hereâs an example:
const talkedRecently = new Set();
if (talkedRecently.has(message.author.id)) {
// If user has cooldown
} else {
// Set cooldown
talkedRecently.add(message.author.id);
setTimeout(() => {
talkedRecently.delete(message.author.id);
}, 3000); // Time
}
else, using quick.db, and add cooldown on db.
Well, in fact, You donât need to use DB, Thereâs a things called Set()
. So hereâs a example of the code below with HOW IT WORKS:
var cooldown = new Set();
<client>.on('message', (message) => {
// Now write the user ID to Set
if (cooldown.has(message.author.id)) {
// Tell to user if h/she's in Cooldown
// It sends then do nothing.
return message.channel.send("You're in cooldown.");
}
// Add cooldown
cooldown.add(message.author.id);
// Make a timeout so the user cooldown is gone after 3 second
setTimeout(() => cooldown.delete(message.author.id), 3000);
// Your code below.....
});
Not working
Yours actually working but it wonât stop spamming âYouâre in cooldownâ any idea why? My discord bot token isnât in another code.
Add statement at first: if (!message.content.startsWith("your-prefix")) return;
Why you should add that statement??
To make your bots respond only if the message starts with your bot prefix
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.