I have 10 humans and 3 user in my discord server but my bot shows only 2 total members, 1 human and 1 bot. Can someone help me fix it so that it shows the whole number of members in the server? This is the code -
Total -
.addField('Total Members', `${interaction.guild.members.cache.size}`, true)
Humans -
.addField('Human Users', `${interaction.guild.members.cache.filter(members => !members.user.bot).size}`, true)
Bots -
.addField('Bots', `${interaction.guild.members.cache.filter(members => members.user.bot).size}`, true)
There are multiple ways to solve this issue
#1: Do you have intents?
const client = new Discord.Client({ intents: ['GUILDS', 'GUILD_MEMBERS'] })
#2: Have you tried fetching all the members in the guild before showing? Discord.js uses something called "cache", where the package stores something in it's database, and you can do whatever you want with it later on without making a new API request to Discord everytime you want to do something (for example, getting a channel's name). Discord.js tries to cache everything it can while it can. If they are not in your cache, then you can fetch it, and add it to the cache manually.