Reputation: 409
So, I want to add a feature for my Discord bot that prevents raids and self-bots. The title briefly specifies my question.
What I want to do is when a user joins my guild, I want the bot to initiate a timer and it begins counting down, so it basically alternates and the timer stops when the next user joins.
When the timer stops, it will determine that if the interval was 7 seconds or less, it will assign them the Restricted Access role and request all of the offending accounts to complete a CAPTCHA to continue. However, if the interval was 8 seconds or more, it will leave them unaffected.
All I will require is a concept of how I could accomplish this such as libraries I might want, any additional details is unnecessary.
Upvotes: 0
Views: 175
Reputation: 711
Use a variable lets say lastJoinedTime
then use this:
client.on(`guildMemberAdd`,function(){
if(Date.now()-8000 < lastJoinedTime){//if the last join was less than 8 secs ago
//Restrict em
}
else {
//They are fine
}
lastJoinedTime = Date.now();
});
another way of checking it is:
if(Date.now()-lastJoinedTime > 8000){}//if last join was less than 8 secs ago.
Upvotes: 1