Reputation: 23
I want to get number of members with a role, but always give me "1":
const server_roles = client.guilds.cache.get('server ID').roles.cache.get('role ID').members.size;
console.log(server_roles)
Log:
Real role member count = 4, not 1
Upvotes: 0
Views: 1170
Reputation: 184
The issue isn't within your code, it's to do with the information bots can access after a recent update. In order to fix this:
Bot
Privileged Gateway Intents
PRESENCE INTENT
and SERVER MEMBERS INTENT
Then, in the code, when initialising your Discord client, add this:
Discord.Client({ ws: { intents: Discord.Intents.ALL } });
That code assumes you've imported the module as Discord
It's quite complex, but after the recent update it's the only way to achieve what you want
Upvotes: 2