#Member Fetching

87 messages · Page 1 of 1 (latest)

raw ruin
#

Hello, I’m using the latest version of discord.js and I have a big problem. My bot is in a single guild with around 320k members, and on the client ready event I fetch all members from that guild. The issue is that when I check guild.members.cache.size, it shows 1–2k fewer members, as if some of them weren’t fetched. This happens every time. Is there any fix?

weak trenchBOT
raw ruin
#

I don’t think an example code snippet is necessary since it’s a very simple project

whole flicker
#

What number do you compare against to determine you're missing 1-2k?

raw ruin
#

And then I run /serverinfo commands from bots like MEE6, Invite Tracker, Dyno

#

They all have same member count

#

My bot can miss 500 members od 1282 or 1921

#

It's always so random

whole flicker
quartz plinthBOT
raw ruin
#

I always had troubles

whole flicker
#

How are you sure? What kind of trouble?

#

Can you show your client constructor

raw ruin
#

When some members aren’t in cache when I get them

whole flicker
#

Can you clarify what you mean by that? Get them where/how?

raw ruin
raw ruin
#

I mean yeah all this does sound insane but I’m certain that something is not working fine

#

This is only with very high member count servers

#

On smaller servers like 5-10k members it’s fine

whole flicker
#

How do you make sure you only .cache.get() after the initial fetch fully resolved?

#

Fetching 320k members will take some time

raw ruin
#

And nothing happens within 3 seconds of bot start

whole flicker
#

How did you determine that? Stating things as facts won't help finding the reason for why it apparently doesn't do what should be a fact too

raw ruin
raw ruin
#

its so random

turbid magnet
#

Try this (the reply chain). The scales are entirely different between our servers, but this helped in my case.
#djs-help-v14 message

whole flicker
raw ruin
whole flicker
#

that is neither of the two alternatives I just told you I'd need

#

imagine I ask you to help me find out why my function for factorial doesn't calculate the right result and all I tell you is that it sometimes returns 20 and sometimes it returns 50. Can you find the reason why?

raw ruin
#

Well I make a new instance of Client with only and only the intents I provided, I listen to clientReady event then I fetch guild via client.guilds.fetch (but same thing happens with guilds cache), I always await fetch so as soon as I have the guild I log guild.members.cache.size, then I do await guild.members.fetch() and I log it again same way

#

Number after members fetch is always different like I told you above

#

But this doesn’t happen with smaller servers

dusty whale
raw ruin
#

Literally PLAIN whole code one index.js file

dusty whale
#

that does not look like a code though

raw ruin
#

Discord bot application is brand new

raw ruin
dusty whale
#

it just says what you think could be happening when the code is running

whole flicker
raw ruin
#

LMAO

whole flicker
#

No. we want code, is that so hard to understand?

raw ruin
#

Sure

#

Wait

raw ruin
raw ruin
# whole flicker No. we want code, is that so hard to understand?
const { Client, GatewayIntentBits } = require('discord.js');

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers
  ]
});

client.once('ready', async () => {
  try {
    const guild = await client.guilds.fetch(``);

    await guild.members.fetch();

    console.log(`Members in cache: ${guild.members.cache.size}`);
  } catch (err) {
    console.error('Error while fetching members:', err);
  }
});

await client.login();
#

And I’m saying

#

It works fine with smaller amount of members

#

But servers like .gg/sinful

#

With 500k or smth

#

It’s not

whole flicker
raw ruin
#

maybe at the moment when I fetch members

#

some of them are unavailable like in discord

#

but that doesnt make a lot of sense

whole flicker
#

Nah, I got another theory at the moment, but need to verify internally first

whole flicker
# raw ruin can i help u somehow

Yes, you actually can. Can you replace your members fetch() call with this:

const members = await guild.members.fetch();
setTimeout(() => console.log(members.size, guild.members.cache.size), 2000);

and tell me if those two numbers always match?

raw ruin
whole flicker
#

Yes, just should wait a bit after the fetch call before logging those

raw ruin
#

alr will send result asap

raw ruin
#

after 2nd restart 228522 228522

#

whole fetch is finished very fast like few seconds

whole flicker
#

Is that in a guild with "just" 228k members or is it in the 500k guild?

#

A single member joining within 2 seconds is not unexpected in such a guild, so those numbers look fine to me atm, sadly not (yet) confirming my theory

whole flicker
#

So the numbers could actually be correct then?

raw ruin
raw ruin
raw ruin
#

but this test wasnt done in that guild

#

i mean fetch is like 95% accurate

#

it just lacks a small amount of members

#

in high member counted servers

whole flicker
#

400 members missing would be an issue on discord's end then. Because they send them in chunks of 1000. it should either be a round number (if the last chunk is missing) or missing thousands of members. I got the feeling this is not djs but upstream, so probably should ask in ddevs #useful-servers

raw ruin
#

i see

whole flicker
#

Does either of those bots have GuildPresences intent? Either by being in less than 100 guilds or by being approved for it?