I tried doing a role count for a specific role with a role ID. My problem now is that the count isn't working properly. I gave 4 people the role and the bot is only counting one person with that role and I don't know why.
My Code:
case 'new':
let roleID = "877984124483400480";
let membersWithRole = message.guild.roles.cache.get(roleID).members;
message.channel.send(`There are ${membersWithRole.size} People with the new Group on our discord`)
break;
I recommend fetching it because cache is unreliable.
case 'new':
let roleID = "877984124483400480";
const rolesCache = await message.guild.roles.cache.fetch()
let membersWithRole(roleID).members;
message.channel.send(`There are ${membersWithRole.size} People with the new Group on our discord`)
break;
Or it can be the intents. Check if you have server members intents and have GUILD_MEMBERS intent in the client options.