Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unstable user count measurement in client.shard.broadcastEval() #10232

Closed
Taka005 opened this issue Apr 27, 2024 · 2 comments
Closed

Unstable user count measurement in client.shard.broadcastEval() #10232

Taka005 opened this issue Apr 27, 2024 · 2 comments

Comments

@Taka005
Copy link

Taka005 commented Apr 27, 2024

Which package is this bug report for?

discord.js

Issue description

I am using client.shard.broadcastEval() to get user and server totals for all shards. (from the code below), but the client.shard.broadcastEval() value is unstable at times and is not returning accurate results.
From my research, this bug is more likely to occur the longer it has been since the BOT was launched.
This bug prevents accurate measurement of statistics
My BOT has 3 shards up and running. This was occurring even with two shards.

Code sample

(await client.shard.broadcastEval(c=>c.guilds.cache.size))
      .reduce((a,c)=>a+c,0);
// returning value is [null,1200,1001]
// For some reason, a null value comes in.

(await client.shard.broadcastEval(c=>c.guilds.cache.reduce((a,g)=>a+g.memberCount,0)))
      .reduce((a,c)=>a+c,0);
// Same here.

Versions

discord.js 14.14.1
Node.js 18.16.0
Ubuntu Server 22.04.4

Issue priority

High (immediate attention needed)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

Guilds, GuildMembers, GuildPresences, GuildMessages, MessageContent

I have tested this issue on a development release

No response

@Qjuh
Copy link
Contributor

Qjuh commented Apr 27, 2024

This sounds like you might have an unavailable Guild on your first shard. So there is a Guild in your <Client>.guilds.cache with available: false property causing its memberCount property to be undefined. Your reduce call then causes the whole sum to become NaN which gets JSONified into null and sent back over the IPC channel to where you call the broadcastEval.
So not a bug in discord.js itself but in your handling of unavailable Guilds. filter the guilds.cache before the reduce calls and you should be good.

@Taka005
Copy link
Author

Taka005 commented Apr 27, 2024

This sounds like you might have an unavailable Guild on your first shard. So there is a Guild in your <Client>.guilds.cache with available: false property causing its memberCount property to be undefined. Your reduce call then causes the whole sum to become NaN which gets JSONified into null and sent back over the IPC channel to where you call the broadcastEval. So not a bug in discord.js itself but in your handling of unavailable Guilds. filter the guilds.cache before the reduce calls and you should be good.

I understand the fix about counting users. Also, all guild counts are a little higher than the actual number of guilds when there are unavailable guilds.

(await client.shard.broadcastEval(c=>c.guilds.cache.size))
      .reduce((a,c)=>a+c,0);
      
 // The number of all guilds is 3100, but when some guilds are not available, the value is 3109, etc.

@discordjs discordjs locked and limited conversation to collaborators Apr 27, 2024
@almostSouji almostSouji converted this issue into discussion #10233 Apr 27, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants