Command Cooldown 1 minute not working discord bot

Here I tried making a command cooldown so people wont be spamming and getting rich fast on my discord bot! The thing is though the code I wrote does not do what I want it to do! It just ignores talkRecently Here is my code:

var eco = require('discord-economy');
const editJsonFile = require("edit-json-file");

const prefix = '.'; 
const talkedRecently = new Set();

exports.run = async (client, message, args, ops) => {
    if (talkedRecently.has(message.author.id)) {
            message.channel.send("Wait 1 minute before getting typing this again. - " + message.author);
    } else {
            var job2 = ['actor/actress','astronaut','baker','barber','biologist','chef','doctor','dentist','farmer','nurse','jounalist','police officer','vet','vocalist','zoologist','waiter/waitress'];

            const user = message.author.id;
            var number = Math.floor(Math.random() * (500 + 1));
            
            let check = eco.FetchBalance(user);
            if(!check) {
                eco.SetBalance(user, 0);
            }

            eco.AddToBalance(user, number)
                
            var job = job2[Math.floor(Math.random() * job2.length)];
            
            message.channel.send(`You have worked as a **${job}** and you have earned ${number}`);
        }

        talkedRecently.add(message.author.id);
        setTimeout(() => {
          // Removes the user from the set after a minute
          talkedRecently.delete(message.author.id);
        }, 60000);
    }
        

Answer

Excluding boilerplate code

var arrOfIds = [];
client.on("message", (msg) => {
arrOfIds.push(msg.author.id)
setInterval(() => {
if(arrOfIds.filter(() => {
return msg.author 
}).length > 10){
msg.reply("Stop spamming")
arrOfIds = arrOfIds.filter(() => {
return !msg.author.id

})
}
}, 60000)
})

Leave a Reply

Your email address will not be published. Required fields are marked *