Slash Command Cooldowns are not working
// command cooldowns
client.slashCooldowns = new Discord.Collection();
const { slashCooldowns } = client;
if (!slashCooldowns.has(interaction.commandName)) {
slashCooldowns.set(interaction.commandName, new Discord.Collection());
}
const now = Date.now();
const timestamps = slashCooldowns.get(interaction.commandName);
console.log('timestamp ', timestamps)
const cooldownAmount = (command.cooldown || 1) * 1000;
console.log('cooldownAmount ', cooldownAmount);
if (timestamps.has(interaction.user.id)) {
const expirationTime = timestamps.get(interaction.user.id) + cooldownAmount;
console.log('expirationTime ', expirationTime)
if (now < expirationTime) {
const timeLeft = (expirationTime - now) / 1000;
console.log('timeLeft ', timeLeft)
return interaction.reply({content: `Please wait ${timeLeft.toFixed(1)} more second(s) before reusing the \`${command.name}\` command.`});
}
}
timestamps.set(interaction.user.id, now);
setTimeout(() => timestamps.delete(interaction.user.id), cooldownAmount); // command cooldowns
client.slashCooldowns = new Discord.Collection();
const { slashCooldowns } = client;
if (!slashCooldowns.has(interaction.commandName)) {
slashCooldowns.set(interaction.commandName, new Discord.Collection());
}
const now = Date.now();
const timestamps = slashCooldowns.get(interaction.commandName);
console.log('timestamp ', timestamps)
const cooldownAmount = (command.cooldown || 1) * 1000;
console.log('cooldownAmount ', cooldownAmount);
if (timestamps.has(interaction.user.id)) {
const expirationTime = timestamps.get(interaction.user.id) + cooldownAmount;
console.log('expirationTime ', expirationTime)
if (now < expirationTime) {
const timeLeft = (expirationTime - now) / 1000;
console.log('timeLeft ', timeLeft)
return interaction.reply({content: `Please wait ${timeLeft.toFixed(1)} more second(s) before reusing the \`${command.name}\` command.`});
}
}
timestamps.set(interaction.user.id, now);
setTimeout(() => timestamps.delete(interaction.user.id), cooldownAmount);/help/help consecutively even when I have the cooldown set to 3000 seconds (to test).As you can see I am logging and it logs up until
expirationTimeexpirationTime that one does not log. just timestamptimestamp and cooldownAmountcooldownAmount.timestamp Collection(0) [Map] {}
cooldownAmount 3000000timestamp Collection(0) [Map] {}
cooldownAmount 3000000That's how those log. Not sure why.