#Guild .memberCount vs .approximateMemberCount?
18 messages · Page 1 of 1 (latest)
- What's your exact discord.js
npm list discord.jsand nodenode -vversion? - Not a discord.js issue? Check out #1081585952654360687.
- 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!
└─ mw-analytics@workspace:.
└─ discord.js@npm:14.14.1 (via npm:^14.14.1)
Node 18.17.0
this.container.metricsManager.writePoint(
new Point("member-count").intField("members", client.guilds.cache.get(env.MAIN_GUILD_ID)!.approximateMemberCount)
);
The error is the Influx client showing me that the guild's .approximateMemberCount is null
(ping for replies please)
In your cache you‘ll have the Guilds sent on login. Those have the memberCount property. If you fetch a guild your bot is not a member of withCounts you‘d get the approximate fields
Options used to fetch a single guild.
Should I be using .membercount or .approximatemembercount?
I'm still getting nulls, I enabled GuildPresences as well
const guild = await client.guilds.fetch({ guild: env.MAIN_GUILD_ID, withCounts: true });
this.container.metricsManager.writePoint(
new Point("member-count")
.intField("members", guild.approximateMemberCount)
.intField("onlineMembers", guild.approximatePresenceCount)
);
.memberCount exists though 
As I said, the guilds your bot is in are cached with exact memberCount on login. Fetching a guild you got in cache will get you the cached one unless you force the fetch (which you never should do with Guilds intent). So use the exact property, no need for approximate one in those cases
ah, I misunderstood what you said. What about for getting members per presence? Do I fetch the full member list??
With GuildPresences intent you‘ll receive all members with presences that aren’t offline on login. So you can filter your member cache by presence.status and the rest that’s unaccounted for will be offline members
Technically in some guilds don't you only get members in VCs if they're over the large guild threshold?
No, with presences intent you get all members if below large threshold and all non-offline members if above
Presences of the members in the guild, will only include non-offline members if the size is greater than large threshold
Ah, nvm, you‘re right for 75k and more members
If your bot does not have the GUILD_PRESENCES Gateway Intent, or if the guild has over 75k members, members and presences returned in this event will only contain your bot and users in voice channels.