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

DJS
53 Replies
d.js toolkit
d.js toolkit•15mo 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
arda•15mo ago
How can i kick all members who doesnt have any role? node v20.5.0 djs 13.16
treble/luna
treble/luna•15mo 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
arda•15mo 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
arda•15mo ago
arda
arda•15mo ago
this doesnt work
treble/luna
treble/luna•15mo ago
fetch the members, cache is unreliable
arda
arda•15mo ago
arda
arda•15mo ago
treble/luna
treble/luna•15mo ago
resolve the promise to a variable
arda
arda•15mo ago
like this?
arda
arda•15mo ago
it says undefined again
treble/luna
treble/luna•15mo ago
do you know how promises work? and roles.fetch is a method
arda
arda•15mo ago
arda
arda•15mo ago
i added await
treble/luna
treble/luna•15mo 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
arda•15mo 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/luna•15mo 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
arda•15mo ago
arda
arda•15mo ago
treble/luna
treble/luna•15mo ago
oh right .cache.get should work i forgot GuildMemberRoleManagers dont have a fetch option, which also answers my doubt
arda
arda•15mo ago
arda
arda•15mo ago
treble/luna
treble/luna•15mo 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
arda•15mo ago
arda
arda•15mo ago
it says this now
arda
arda•15mo ago
treble/luna
treble/luna•15mo ago
remove the await and call m.roles.cache.size directly
arda
arda•15mo ago
okay i fixed
arda
arda•15mo ago
arda
arda•15mo ago
arda
arda•15mo ago
so how can i hick all theese members? i have 1000+ members in my discord does it need interval?
treble/luna
treble/luna•15mo ago
you will need an interval yes
arda
arda•15mo ago
how can i set this to interval
d.js docs
d.js docs•15mo 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/luna•15mo ago
also double check whether those members actually have no roles
arda
arda•15mo ago
why am i gonna add 2 if function?
arda
arda•15mo ago
arda
arda•15mo 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 docs•15mo ago
method GuildMemberManager#prune() Prunes members from the guild based on how long they have been inactive.
treble/luna
treble/luna•15mo ago
oh right wasnt sure whether that kicked members without roles or just inactive accounts
arda
arda•15mo ago
i want kick without roles why
arda
arda•15mo ago
isn't this enough?
arda
arda•15mo ago
with interval
arda
arda•15mo ago
arda
arda•15mo 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/luna•15mo ago
No 1) dont spoonfeed 2) that is api spam 3) qjuh gave them an answer 4) role cache wont ever be 0 .
arda
arda•15mo ago
are you telling me
treble/luna
treble/luna•15mo ago
Read it
arda
arda•15mo ago
treble/luna
treble/luna•15mo ago
Read this And also, the 'no' should hint you
arda
arda•15mo ago
no should'nt hint me because the message is deleted and i didnt write this message
Unknown User
Unknown User•15mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server