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 toolkit11mo 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
ShompiFlen11mo ago
where are you logging these values show the code you are running
Sevlow
Sevlow11mo 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
ShompiFlen11mo ago
ok show me a picture of the embed
Sevlow
Sevlow11mo ago
No description
ShompiFlen
ShompiFlen11mo 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
Sevlow11mo ago
There is two bots online, me online and two bots offline okay I believe I have the GuildMembers intent
ShompiFlen
ShompiFlen11mo 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
Sevlow11mo ago
still, two bot members are offline and it still shows one
ShompiFlen
ShompiFlen11mo ago
are you counting your own bot as the one thats online
Sevlow
Sevlow11mo ago
yup...
ShompiFlen
ShompiFlen11mo ago
try doing this before doing the filtering
Sevlow
Sevlow11mo ago
k okay, it worked, thank you!
ShompiFlen
ShompiFlen11mo ago
mukiThumbsup
Want results from more Discord servers?
Add your server