Problem with counting members with catch

Can someone help me, cuz I have a problem with counting members. Generally, I am trying to count both bot count and non bots count but while the Guild.memberCount is equal 5, both the counts are equal 5(should be 4 bots and 1 person) Code:
g.members.cache.filter(m => m.user.bot).size
g.members.cache.filter(m => !m.user.bot).size
g.members.cache.filter(m => m.user.bot).size
g.members.cache.filter(m => !m.user.bot).size
14 Replies
d.js toolkit
d.js toolkit14mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
ShompiFlen
ShompiFlen14mo ago
where are you logging these values show the code you are running
Sevlow
SevlowOP14mo ago
In an embed
const { EmbedBuilder } = require("../../../node_modules/discord.js")
let own = client.users.cache.get(g.ownerId)
let embd = new EmbedBuilder().setTitle("Member count").setColor("Random").setFooter({text: `Used by ${msg.author.tag} | ${msg.author.id}!`, iconURL: msg.author.avatarURL()})
.setThumbnail(g.iconURL()).setDescription(
`
Members: ${g.memberCount}
• Bots: ${g.members.cache.filter(m => m.user.bot).size}
• Humans: ${g.members.cache.filter(m => !m.user.bot).size}`
)
msg.channel.send({embeds:[embd]})
const { EmbedBuilder } = require("../../../node_modules/discord.js")
let own = client.users.cache.get(g.ownerId)
let embd = new EmbedBuilder().setTitle("Member count").setColor("Random").setFooter({text: `Used by ${msg.author.tag} | ${msg.author.id}!`, iconURL: msg.author.avatarURL()})
.setThumbnail(g.iconURL()).setDescription(
`
Members: ${g.memberCount}
• Bots: ${g.members.cache.filter(m => m.user.bot).size}
• Humans: ${g.members.cache.filter(m => !m.user.bot).size}`
)
msg.channel.send({embeds:[embd]})
ShompiFlen
ShompiFlen14mo ago
ok show me a picture of the embed
Sevlow
SevlowOP14mo ago
No description
ShompiFlen
ShompiFlen14mo ago
alright i was expecting something like that you said both numbers were 5 but they aren't are the other members offline? if not then you are probably missing the guild members intent, that could be one issue, if you dont have it then only members that interact with your bot are going to be cached
Sevlow
SevlowOP14mo ago
There is two bots online, me online and two bots offline okay I believe I have the GuildMembers intent
ShompiFlen
ShompiFlen14mo ago
it not caching the offline members is okay, discord doesn't send them. if you want a more accurate number you need to fetch all members from the guild before running this command await guild.members.fetch() should be enough to cache them
Sevlow
SevlowOP14mo ago
still, two bot members are offline and it still shows one
ShompiFlen
ShompiFlen14mo ago
are you counting your own bot as the one thats online
Sevlow
SevlowOP14mo ago
yup...
ShompiFlen
ShompiFlen14mo ago
try doing this before doing the filtering
Sevlow
SevlowOP14mo ago
k okay, it worked, thank you!
ShompiFlen
ShompiFlen14mo ago
mukiThumbsup
Want results from more Discord servers?
Add your server