For my command cooldown system, I used this Code:
if (!cooldowns.has(command.name)) {
cooldowns.set(command.name, new Discord.Collection());
}
const current_time = Date.now();
const time_stamps = cooldowns.get(command.name);
const cooldown_amount = command.cooldown * 1000;
if (time_stamps.has(message.author.id)) {
const expiration_time = time_stamps.get(message.author.id) cooldown_amount;
if (current_time < expiration_time) {
const time_left = (expiration_time - current_time) / 1000;
return message.reply(`${time_left.toFixed(1)}s cooldown`).then((msg) => {
setTimeout(() => msg.delete(), 3000);
});
}
}
time_stamps.set(message.author.id, current_time);
setTimeout(() => time_stamps.delete(message.author.id), cooldown_amount);
That for example returns: '4.2s cooldown'. I want to know how can I remove the decimal number: '4s cooldown'.
Notes: I am using discord.js v13 and node.js v16
CodePudding user response:
To remove decimal number you can round a number you are sending using Math.round()
or also you can use Math.trunc()
to simply remove it as @MZPL said!
CodePudding user response:
Change the following
return message.reply( `${time_left.toFixed(1)}s cooldown`)
to
return message.reply( `${time_left.toFixed()}s cooldown`)
You can also use Math.trunc() to achieve that.