Creating a cooldown system that works individually per user and not for the command itself

Hi I’ve been working on a bot and wanted to make a cooldown for the user for 10 mins if they use the command again I created this system that works as a cooldown but for all users how would I make it for only the user of the command and have it be individual.

if(message == '!joinqueue') {

        if(!block) {
            
            client.say(channel, `@${user.username}, Joined The Queue!`);
        
            queue.push(`${user.username}`);

            console.log(queue);

            block = true
            setTimeout(() => {
                block = false;
            }, (60 * 10000))
        }
        else {
            client.say(channel, `@${user.username} Please Wait Before Doing This Command Again`)
        }

Please visit stackoverflow for general programming questions

While said above, you should probably use StackOverflow for this type of question, here is how I would approach this and create a queue command, assuming you’re using tmi.js.

This works because block can be an object of User IDs with blocking states.

if (message.toLowerCase() == '!joinqueue') {

    if (!block[user['user-id']]) {
            
        client.say(channel, `@${user.username}, Joined The Queue!`);
        queue.push(`${user.username}`);

        block[user['user-id']] = true;

        setTimeout(() => {
            delete block[user['user-id']];
        }, (60 * 10000));
        
    } else {
        client.say(channel, `@${user.username} Please Wait Before Doing This Command Again`);
    }
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.