1

So I'm Having A Problem I Want To See How Many Members My Server Has But It Only Shows 5 I Have More Than 5 Members My Server My Code Is

message.member.guild.members.cache.size

Is There A Way To Fix This? Or Am I Doing Something Wrong...

3 Answers 3

2

The easiest way to get the total count of the members in a guild is to use guild.memberCount.

let membercount = message.guild.memberCount
message.channel.send(membercount + " members in this guild.")
0

You may need to cache the members. The quicker way to do it is like this:

let members = await message.guild.members.fetch();
let amount = members.size; //should give the correct amount

The fetch() method returns a promise, the collection of members in the guild. You must await it though.

Remember to put it in an async function!

0

You can choose this

let members = (await guild.members.fetch()).filter(m => !m.user.bot); //Filter only the Members
let membersAmount = members.size; //give the correct amount

instead message.member.guild.members.cache.size

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.