#role.members.size returns 1 instead of the actual amount

1 messages · Page 1 of 1 (latest)

merry grove
#

Hello! I want to get how many members are in a specific role, but can't get the actual amount. You see, the size property returns 1 but the actual amount is 3. Here is the code:

const mention = message.mentions.roles.first()
const role = message.guild.roles.cache.get(mention.id)
console.log(role.members.size)

NOTE: I have tried this in v13, v14 and even in v12 and all of them returned 1.
Any help will be appreciated, thank you!

solid thicket
#

the problem is that role.members rely on the members cache of the guild. Normally, you never have all GuildMembers cached. You could fetch them beforehand if you really want to