1

I'm making a server info command and i want it to say how many humans and bots are in the server, here's the part of the embed that should do that:

{ name: 'Human members: ', value: message.guild.members.cache.filter(member => !member.user.bot).size, inline: true}, 
{ name: 'Bots members: ', value: message.guild.members.cache.filter(member => member.user.bot).size, inline: true},  
            

But this is what i get: enter image description here

I'm trying the command in a server with like 50 humans and 10 bots, i hope you can help

tom.js
  • 232
  • 1
  • 2
  • 13
  • 1
    Does this answer your question? [None of my discord.js guildmember events are emitting, my user caches are basically empty, and my functions are timing out?](https://stackoverflow.com/questions/64559390/none-of-my-discord-js-guildmember-events-are-emitting-my-user-caches-are-basica) – Lioness100 Jul 19 '21 at 10:50

1 Answers1

0

Try to fetch the members before you check the cache. members.fetch() will fetch members from Discord, even if they're offline. It returns a collection of GuildMember objects so you don't even need the cache property any more:

let members = await message.guild.members.fetch()

// ...
.addFields(
  { name: 'Human members: ', value: members.filter(member => !member.user.bot).size, inline: true}, 
  { name: 'Bots members: ', value: members.filter(member => member.user.bot).size, inline: true},  
)
Zsolt Meszaros
  • 21,961
  • 19
  • 54
  • 57
  • I'm using module.exports and stuff, and i tried putting async before execute(message, args), but the command doesn't work entirely, and vs code gives no error – tom.js Jul 19 '21 at 11:20
  • So is it `async execute(message, args) {...` now? Have you tried to check what the value of `members` is? – Zsolt Meszaros Jul 19 '21 at 11:22
  • Yes execute is now like that, but i haven't tried checking `members` value – tom.js Jul 19 '21 at 11:25
  • 1
    Any update on this? Have you logged `members`? Have you found the problem? I tried it with my bot and it worked fine. Have you enabled `GUILD_MEMBERS` intents? – Zsolt Meszaros Jul 19 '21 at 12:13