0
I am with a saving command and wanted that when the user, who already used the command, wait 30 minutes but the code returns an error informing remaining time to use the command again as I do ?
-- CODIGO
const cooldown = new Set();
const db = require('quick.db');
const ms = require('ms');
module.exports.run = async (client, message, args) => {
if(!message.content.startsWith(','))return;
const user = message.author;
const author = await db.fetch(`work_${message.guild.id}_${user.id}`)
const timeout = 1800000;
if (author !== null && timeout - (Date.now() - message.author) > 0) {
const time = ms(timeout - (Date.now() - message.author));
if (cooldown.has(message.author.id)){
message.channel.send(` ${user} | <a:negado:872682572965118033> Você já trabalhou hoje,Tente denovo em **${timeout} minutos**`)
} else {
const replies = ['Programador','Construtor','Bancário','Motorista','Chefe','Mecanico']
const result = Math.floor((Math.random() * replies.length));
const amount = Math.floor(Math.random() * 1000) + 1;
message.channel.send(` ${user} | <a:azul:876222068688052315> Você trabalhou como **${replies[result]}** e Ganhou Salario De **${amount}** `)
db.add(`money_${message.guild.id}_${user.id}`, amount)
db.set(`work_${message.guild.id}_${user.id}`, Date.now())
cooldown.add(message.author.id);
setTimeout(() => {
cooldown.delete(message.author.id)
}, `${timeout}`);
};
}
}
I don’t get it @Danizavtz
– Asael Dos Anjos De Andrade
Oh yes, someone already edited the question, now it is already with correct appearance.
– Danizavtz
Can you help me @Danizavtz
– Asael Dos Anjos De Andrade
I can’t, I don’t understand any of those libs you’re using.
– Danizavtz
is for a bot application within Discord @Danizavtz
– Asael Dos Anjos De Andrade
const time = ms(timeout - (Date.now() - message.author));
This is already confusing,message.author
would be a number. But anyway, what I would do is use aMap
in place ofSet
associating the user id and a waiting timestamp, would search for id, check the current timestamp with the user’s limit and return a time difference message if it is positive value.– Cmte Cardeal
@Cmtecardeal Only Suggests Changing the "Set" to "Map"
– Asael Dos Anjos De Andrade