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

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

Did you find this page helpful?