How can i kick all members who doesnt have any role?

DJS
53 Replies
d.js toolkit
d.js toolkit17mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
arda
ardaOP17mo ago
How can i kick all members who doesnt have any role? node v20.5.0 djs 13.16
treble/luna
treble/luna17mo ago
you'd have to filter through the guild members, check their roles and then kick them. Do this on an interval though, to not get ratelimited
arda
ardaOP17mo ago
how can i do this I used to have bots, I was trying so hard, but when I took a break, I forgot.
arda
ardaOP17mo ago
arda
ardaOP17mo ago
this doesnt work
treble/luna
treble/luna17mo ago
fetch the members, cache is unreliable
arda
ardaOP17mo ago
arda
ardaOP17mo ago
treble/luna
treble/luna17mo ago
resolve the promise to a variable
arda
ardaOP17mo ago
like this?
arda
ardaOP17mo ago
it says undefined again
treble/luna
treble/luna17mo ago
do you know how promises work? and roles.fetch is a method
arda
ardaOP17mo ago
arda
ardaOP17mo ago
i added await
treble/luna
treble/luna17mo ago
yeah thats not how promises work reolve it to a variable then call .map on it in which you will have to resolve the promise roles.fetch() returns
arda
ardaOP17mo ago
how can i do it really, such questions were asked to me in the past, I had a lot of bots and it was used well, but I can't remember and discord.js has also changed so if you can help me a bit, I'd appreciate it <3 i know i'm struggling but i need help right now
treble/luna
treble/luna17mo ago
let a = await ...fetch()

a.map(async m => {
const roles = await m.roles.fetch()
//check role stuff
})
let a = await ...fetch()

a.map(async m => {
const roles = await m.roles.fetch()
//check role stuff
})
i dont know if you need to fetch the role though they might be cached when fetching the members but i'm not 100% sure
arda
ardaOP17mo ago
arda
ardaOP17mo ago
treble/luna
treble/luna17mo ago
oh right .cache.get should work i forgot GuildMemberRoleManagers dont have a fetch option, which also answers my doubt
arda
ardaOP17mo ago
arda
ardaOP17mo ago
treble/luna
treble/luna17mo ago
oh right you're checking if they have any roles, then check cache.size should be 1 if they dont have any roles
arda
ardaOP17mo ago
arda
ardaOP17mo ago
it says this now
arda
ardaOP17mo ago
treble/luna
treble/luna17mo ago
remove the await and call m.roles.cache.size directly
arda
ardaOP17mo ago
okay i fixed
arda
ardaOP17mo ago
arda
ardaOP17mo ago
arda
ardaOP17mo ago
so how can i hick all theese members? i have 1000+ members in my discord does it need interval?
treble/luna
treble/luna17mo ago
you will need an interval yes
arda
ardaOP17mo ago
how can i set this to interval
d.js docs
d.js docs17mo ago
mdn setInterval() global function The setInterval() method, offered on the Window and Worker interfaces, repeatedly calls a function or executes a code snippet, with a fixed time delay between each call.
treble/luna
treble/luna17mo ago
also double check whether those members actually have no roles
arda
ardaOP17mo ago
why am i gonna add 2 if function?
arda
ardaOP17mo ago
arda
ardaOP17mo ago
like this? 2 if 2 checking By the way, was == required for it to detect numbers === so let me do something accordingly so that there is no problem with the bot.
d.js docs
d.js docs17mo ago
method GuildMemberManager#prune() Prunes members from the guild based on how long they have been inactive.
treble/luna
treble/luna17mo ago
oh right wasnt sure whether that kicked members without roles or just inactive accounts
arda
ardaOP17mo ago
i want kick without roles why
arda
ardaOP17mo ago
isn't this enough?
arda
ardaOP17mo ago
with interval
arda
ardaOP17mo ago
arda
ardaOP17mo ago
is interval true? kicking no role members with 5 sec interval Not everyone has to be a software developer. sorry about that but thats it prune is kicking inactive members right? so why i am gonna use this instead of no role kicking how can i use this
treble/luna
treble/luna17mo ago
No 1) dont spoonfeed 2) that is api spam 3) qjuh gave them an answer 4) role cache wont ever be 0 .
arda
ardaOP17mo ago
are you telling me
treble/luna
treble/luna17mo ago
Read it
arda
ardaOP17mo ago
treble/luna
treble/luna17mo ago
Read this And also, the 'no' should hint you
arda
ardaOP17mo ago
no should'nt hint me because the message is deleted and i didnt write this message
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server