#Error, trying to update users without roles but nothing happens

28 messages · Page 1 of 1 (latest)

wide surge
#

Im using this function to add a role to the users who dont have one, tested it in my test server but trying it in a big one it's not working:

async function usersWithoutRole(){
    var guild = client.guilds.cache.get(guildId);
    var members = guild.members.cache.filter(member => member._roles.length == 0);       
    if (members.length == 0){
        console.log('Looks like everyone has a role already.');
    }
    else{  
        for (let member of members.keys()){
            //console.log(member);
            let user = await guild.members.fetch(member);
            user.roles.add(newUserRole);    
        }
    }
}

And I'm calling it in

....
    await usersWithoutRole();
    console.log('Ready!');
});```
rotund kiteBOT
#

• 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.

wide surge
lone sage
#

ofc it ain't working, u are spamming the API, also why does ur tag says 13.11 when u aren't even in that version 🤔

wide surge
wide surge
lone sage
#

by not doing it.

#

everyone role exist for a reason.

radiant harness
#

lol

#

they are getting no members because uncached

lone sage
#

sad

radiant harness
#

But scp is still right. Don't do it, it's api spam and everyone role should be used

wide surge
#

Thank you for your comments @lone sage @radiant harness
The thing is, in my server, everyone role is not allowed to access any channel (to prevent bots access to the list of users), and then i have 2 roles: new user (assigned when someone joins the server client.on('guildMemberAdd' ) and the Verified one
Sometimes the bot reboots with ~1min offline, and if someone enters the server at that moment, the role "new user" won't be added.
What I want is, when the bot is starting again, check all the users that doesn't have a role, and add them the role "new user"
Is there any other way of gathering this users without spamming the API?

rotund kiteBOT
#

Join roles have often unwanted side effects!
• Assigning a role bypasses verification and security features on Discord
• Can quickly become API spam and hit rate limits rapidly
• The server depends on the bot being online and the API to be functional
The @everyone role is much better suited for announcements

lone sage
#

i just told u how to do it without API spam 🐌

wide surge
fierce stump
#

looks like it's probably because you never fetch all members

#

you filter the cache and then fetch members that were already in cache

#

instead, fetch all guild members once and filter from that

#

also

not allowed to access any channel (to prevent bots access to the list of users)
that's not really how that works

wide surge
wide surge
fierce stump
#

well, let me actually test it

#

and that's for server where there's only 311 members with the role that limits the access to just 2 channels

#

including the test bot, that was invited without any perms

#

btw, i didn't even fetch the members in the server, that's just what i got upon identify, but that's influenced by intents

wide surge
#

I'll send you a DM about what I mean