0

Pls use role id. Here's my codeline :

client.on('message', message =>{

let roleID = "786148346846117940";
let memberCount = message.guild.roles.cache.get('roleID').members.size;
 console.log(memberCount)   
});

I tried this code but somehow even when 1 member has the role it send me:

0
0

But when i am the person who has the role then i get:

1
1
James Z
  • 12,209
  • 10
  • 24
  • 44

1 Answers1

1

You passed a String instead of the variable roleID to Collection#get. So instead of 786148346846117940, it is roleID.


client.on("message", message => {
    const Role = message.guild.roles.cache.get("786148346846117940");

    console.log(Role ? `Role ${Role.name} has ${Role.members.size} members.` : `The role doesn't exist.`);
});
Jakye
  • 6,440
  • 3
  • 19
  • 38