1

I was making a member count command for my bot which would show the Total, Members, Bots of the server. I have given my code below which works perfectly but the problem is, the bot shows the members as 1 and bots as 2 while the total members is correct.

    if (message.content.startsWith('$membercount')) {
      const memberCount = message.guild.members.cache.filter(member => !member.user.bot).size;
      const totalCount = message.guild.memberCount
      const botCount = message.guild.members.cache.filter(member => member.user.bot).size;

      const embed = new Discord.MessageEmbed()
      .setTitle(`${message.guild}`)
      .addField('Total', totalCount)
      .addField('Members', memberCount)
      .addField('Bots', botCount)

      message.channel.send(embed)

    }
Toasty
  • 1,850
  • 1
  • 6
  • 21
Darshan B
  • 658
  • 1
  • 5
  • 19

2 Answers2

0

I've copied your code and tried it with my bot. It worked perfectly... Maybe you are using old discord.js but I don't think this could be a problem. How many bots and members are actually in your server?

0

You'll need to enable "GUILD_MEMBERS" intent for that.
If you don't know about Gateway intents then take this as reference
If your bot is in 100+ servers it'll need to be verified and whitelisting

Akio
  • 721
  • 2
  • 6
  • 21