I'm new at coding, I'm making a discord bot, and I'd like to make a command where all members need to wait a certain time before using it again, but some of them doesn't need to wait the same time.
For exemple: member with role X wait 20 seconds and member with role Y wait 10 seconds.
The problem is that I'm unable to make it work with a npm package called humanize-duration to make a time remaining. The embed description doesn't show the correct timestamp. Maybe it's a mistake made by me.
What I tried to fix my issue?
I tried to read the discord.js docs, humanize-duration docs, and this post but I couldn't fix it. Also, I don't get any errors. By the way, I use a command handler.
This is the code I use as exemple(ping command):
const Discord = require("discord.js");
const humanizeDuration = require("humanize-duration");
let cooldown = new Set();
module.exports = {
name: "ping",
description: "It shows the bot latency.",
execute(client, message, args) {
let guild = client.guilds.cache.get("828376495969402901");
let member = guild.members.cache.get(message.author.id);
if(cooldown.has(message.author.id) && !member.roles.cache.has("830503345251680298")) {
const remaining = humanizeDuration(cooldown.has(message.author.id) && !member.roles.cache.has("830503345251680298") - Date.now(), { units: ["s"], round: true, language: "en" });
const cooldownEmbed = new Discord.MessageEmbed()
.setTitle(`Slow down, bud`)
.setDescription(`You can run \`ping\` again in **${remaining}**.\nThe default cooldown is \`20s\`, but boosters can only wait \`10s\`!`)
.setColor(`RANDOM`);
return message.channel.send(cooldownEmbed)
}else if (cooldown.has(message.author.id) && member.roles.cache.has("830503345251680298")) {
const remaining = humanizeDuration(cooldown.has(message.author.id) && member.roles.cache.has("830503345251680298") - Date.now(), { units: ["s"], round: true, language: "en" });
const cooldownEmbed = new Discord.MessageEmbed()
.setTitle(`Too fast`)
.setDescription(`You can run this command again in **${remaining}**. (booster perk)`)
.setColor(`RANDOM`);
return message.channel.send(cooldownEmbed)
}
if(cooldown.add(message.author.id) && !member.roles.cache.has("830503345251680298")) {
setTimeout(() => {
cooldown.delete(message.author.id) && !member.roles.cache.has("830503345251680298")
}, 10000)
}else if(cooldown.add(message.author.id) && member.roles.cache.has("830503345251680298")) {
setTimeout(() => {
cooldown.delete(message.author.id) && member.roles.cache.has("830503345251680298")
}, 2000)
}
message.channel.send('Pinging...').then(message => {
const embed = new Discord.MessageEmbed()
.setDescription(`Pong! :ping_pong: \`${Date.now() - message.createdTimestamp} ms\``)
.setColor(`RANDOM`);
message.edit(" ", embed);
})
}
}
Thank you very much for the help in advance.
Kind Regards.
