My anti-raid function doesn't work
Hello, I want to create a function that kicks new members during 30 seconds if 10 members join in 10 seconds. I am on this for now 1 entire day, but cant find how to do it. Could you help me please ?
41 Replies
• What's your exact discord.js
npm list discord.js
and node node -v
version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.node v17.3.0
discord.js v14.1.1
for the moment I have this
put the if statement inside the event otherwise it will never trigger
that's a very simple way of doing it but it should work
also unless you're importing setTimeout from node:timers/promises that syntax is invalid
okay ty
Okay so now I have this, but still doesnt work
the
console.log(member.user.tag+" joined the guild !");
and console.log(memberadd)
works and return what they should
So i think the issue is from the while, but i cant figure whereYour while loop only executes once because it’s outside in global
Your while condition isn't defined, you've just set the condition as
true
. I think you mean to have it set a while (raidmode) {
while raidmode = trueI’d probably advise against a while(true) anyway..... you could easily handle it better in the event logic without a loop.
Wdym
Everytime a member joins, the event is fired. Check if raidmode is true and run your code inside that
Something like that would likely lock the runtime if the loop doesn’t break immediately.
There’s also a field in guild members that tells you when they joined. So you could keep a record of the last 10 members to join and check if 10 seconds has elapsed since the first member on the list joined.
Yes I thought about that but I dont know at all how to do it, so I tried doing it like it is right now
<GuildMember>.joinedTimestamp
Then just compare the newest member's timestamp to the previous members
Okay thanks
How do I compare ?
Check out array.slice and array.push as well
That field is actually a number so you could just subtract
Probably subtract the previous timestamp from the new timestamp, which will give you the difference in milliseconds difference. Then an if statement?
okay
I'll try that
thanks
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
the 30s is the duration of the raidmode
so it kicks new users during 30s
Im trying this, seems to be a good way to do it
Could you show your code or not ?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
okay ty
smth like this ?
I’m not sure how you could get the count of members that join within a 10 second time frame without creating a 10 second timeout every time a member joins. At that point it gets really messy trying to keep track of each timeout separately.
The last if statement won’t do anything. It’s only going to fire once
The interval might work though.
so how could I do the last statement work
put it in a while ?
tbh if i can make this work without having to compare an array i'll be happy xD
That while loop though will end up creating a ton of intervals
yeah bot doesnt start
The way it is now the while loop would execute forever
js heap out of memory
Yeah it created intervals until crash
ye
No loops.
So what statement should I use ?
If you reallllly want an interval just leave it without the loop
its not that i want to do an interval
its that i dont want to do an array if possible xD
for the timeout i should put it in a loop, no ?
while raidmode = true
it will exit the loop in 30 s
Well think about when you want to start the 30s timer.
Oh i should put it under raidmode = true, right ?
Like this ?
having this on an interval is stupid, you only need the checks in the event
a member wont join without emitting an event
so checking when there isn't one is just a waste of resources
sorry i'm new to discord js
could you elaborate your point please ?
Guess I'll just have to do an array you do the countdown ?
nvm i did it
No, you’re new to JS
Idek what you wanna do with an array
Im just saying
Move your check to the event
And remove the loop
kinda, only did 2 years of web dev
Well then you’re new to node
this event ?
client.on("guildMemberAdd",
yes im new to node