Discord Cooldown Commands

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 :frowning: . 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 :frowning:

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.