Set a timeout by guild in discord.js instead of by user?

You know there’s code where you can do:

const talkedRecently = new Set();
if (talkedRecently.has(message.author.id)) {
                message.channel.send("**Wait 1 hour before using the coinflip command again, **" + "<@" + message.author.id + ">");
        } else {
//Your code

}
            talkedRecently.add(message.author.id);
        setTimeout(() => {
          // Removes the user from the set after an hour
          talkedRecently.delete(message.author.id);
        }, 3600000); 

This code basically makes it so a user can’t use the command for an hour. The problem here is that I want it so it’s per guild, not user. If someone uses the command in one server, they can’t use it in another server because the set is created by user not by guild. Is there a way I can make it by guild so its 1 hour per user per guild?

You could add a validation layer like

if(guild.id === whatever && message.author.id ) {
//do something
}
1 Like

omg, I tried doing what you did but it was the complete opposite, thanks.

1 Like