Reputation: 3
I want to make a command with a max of two daily uses per person
Here is my code:
module.exports = {
name: 'pmention',
description: 'mention private',
execute(message, args) {
if(message.member.roles.cache.has('776430878359814194') || message.member.permissions.has('ADMINSTRATOR')){
message.delete();
message.channel.send('<@&776941870667792395>')
}else{
message.channel.send(':x: **You do not have permission to do that.**')
}
}
}
Upvotes: 0
Views: 217
Reputation: 1056
You can use a Set
to do this, however it will not keep the users in the set if the bot crashes or you shut it down, for that you will probably need to put them in a database or something more permanent.
Here is an example:
let cooldown = new Set();
if(cooldown.has(message.author.id)) {
message.channel.send("You can only use this command twice a day.");
} else {
// Your code here
cooldown.add(message.author.id);
setTimeout(() => {
talkedRecently.delete(msg.author.id);
}, 43200000);
}
43200000
is 12 hours in milliseconds. Twice a day is equivalent to once every twelve hours, but if you wanted the user to be able to call it twice daily, but one after the other (a few seconds apart) then you should probably look into using a database, such as SQLite or MongoDB and then setup a job to clear their entries once a day.
Upvotes: 1