← Back to Community
How to make cooldowns in discord.js
Profile icon
[deleted]

Hey there, how do i make cooldowns for discord.js commands?

I have

const Discord = require('discord.js') module.exports = { name: "test", cooldown: 10, async execute(message, args) { // code } }

and what discord.js guide tells me to. But the cooldown lasts 3s not 10s or 10ms however its read

Comments
hotnewtop
Profile icon
LordSoloOfficial
const Timeout = new Collection(); let command = bot.commands.get(cmd) if(!command) command = bot.commands.get(bot.aliases.get(cmd)); if (command) { if(command.cooldown) { if(Timeout.has(`${command.name}${message.author.id}`)) return message.channel.send(`You are on a \`${ms(Timeout.get(`${command.name}${message.author.id}`) - Date.now(), {long : true})}\` cooldown.`) command.execute(bot, message, args) Timeout.set(`${command.name}${message.author.id}`, Date.now() + command.cooldown) setTimeout(() => { Timeout.delete(`${command.name}${message.author.id}`) }, command.cooldown) } else command.execute(bot, message, args); }