a simple (discord bots anything really) cooldown for commands made using quick.db
npm install command-cooldown
const cmdCD = require('command-cooldown');
client.on('message',async message => {
if (message.content == "ping") {
let cd = await cmdCD.checkCoolDown(message.author.id, "cmd-ping");
if (cd.res.spam) return "this user spams this command, i will not do any thing in order to not get rate limted";
if (!cd.res.ready) return message.reply(Reamaining ${(cd.res.rem / 1000).toFixed(1)}s);
message.reply(My Ping is : ( ${client.ws.ping}Ms ));
cmdCD.addCoolDown(message.author.id, 5000, "cmd-ping");
};
});
`
Response
it will output remaning time in ms so you could do anything :)
`
{
ready : Boolean // whether the command is ready to user or not
rem : Timestapms //remaining time
cmd : String // cooldown's command name
spam : Boolean // if the user is spamming the cooldown
}
`
$3
These are the keys in the options you can pass.
- ID, type : string or number, the cooldown author id
- 5000 , type : Timestamp, the cooldown duration in ms.
- "cmd-name" , type : String, the cooldown command name this helps to add multi cooldowns NOT REQUIERD.
`
cmdCD.addCoolDown(ID, 5000, "cmd-name");
^^ ^^^^
* ^ = required
``