I want to see how many members have a certain role in my server. To do so I am using the code:
const bots = guild.roles.cache.find(role => role.name == "Bots"); console.log(bots.members.cache.size);
which was the solution provided in this question: How can I check how many people have a role in a specific discord server?
However, I keep getting this error: TypeError: Cannot read property 'size' of undefined.
TypeError: Cannot read property 'size' of undefined
Role#members itself returns a Collection<Snowflake, GuildMember>, so just use
Role#members
Collection<Snowflake, GuildMember>
bots.members.size
and it should work.
https://discord.js.org/#/docs/main/stable/class/Role?scrollTo=members
1.4m articles
1.4m replys
5 comments
56.9k users