Why it doesn't show the right member online?

I've checked this in my server (the photo shows below), and it is not as same as with what Discord actually show all online members. Here's the code:
// Constants
let guild = interaction.client.guilds.cache.get(interaction.guild.id);

const onlineTol = guild.members.cache.filter(member => member.presence).size;
const offlineTol = guild.members.cache.filter(member => !member.presence || member.presence.status === 'offline').size;
// Constants
let guild = interaction.client.guilds.cache.get(interaction.guild.id);

const onlineTol = guild.members.cache.filter(member => member.presence).size;
const offlineTol = guild.members.cache.filter(member => !member.presence || member.presence.status === 'offline').size;
17 Replies
d.js docs
d.js docs3y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers. Tag suggestion for @harshfeudal: Getting your bot's member countclient.users.cache.size is unreliable because it will only return cached users • The preferred method is using collection.reduce() on client.guilds.cache
client.guilds.cache.reduce((acc, guild) => acc + guild.memberCount, 0)
client.guilds.cache.reduce((acc, guild) => acc + guild.memberCount, 0)
harshfeudal
harshfeudalOP3y ago
i did that before, as I've asked, and it still show the same with this way, so idk :(
Syjalo
Syjalo3y ago
1) You need GUILD_MEMBERS and GUILD_PRESENCES intents 2) You should fetch all members 3) Online members can have dnd or idle statuses
harshfeudal
harshfeudalOP3y ago
i use admin intents
Syjalo
Syjalo3y ago
4) The presence can exist with offline status
Syjalo
Syjalo3y ago
It's permission, not intent
d.js docs
d.js docs3y ago
Tag suggestion for @harshfeudal: • Websocket intents limit events and decrease memory usage: learn more • See what intents you need here
harshfeudal
harshfeudalOP3y ago
const client = new Client({
intents: 3276799,
});
const client = new Client({
intents: 3276799,
});
d.js docs
d.js docs3y ago
Tag suggestion for @harshfeudal: We highly recommend only specifying the intents you actually need. • Note, that 98303, 32767 or whatever other magic number you read represents "all intents", somewhere, gets outdated as soon as new intents are introduced. • The number will always represent the same set of intents, excluding new ones, there is no magic "all intents" bit.
harshfeudal
harshfeudalOP3y ago
hmm okay
harshfeudal
harshfeudalOP3y ago
it's correct in small server, but it doesn't in larger one :(
souji
souji3y ago
your code relies on the cache and does not fetch members as said here (reply)
harshfeudal
harshfeudalOP3y ago
no i have fixed
harshfeudal
harshfeudalOP3y ago
and fix intents too
harshfeudal
harshfeudalOP3y ago
harshfeudal
harshfeudalOP3y ago
i've just checked, all servers can, but idk why it's always missing 4 members online in my server :( all others can get all ive checked, my bot has updated members online more faster than Discord. What I look onto Discord stats is the stable number one, however my bot update every second.
Want results from more Discord servers?
Add your server