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?
#Member Fetching
87 messages · Page 1 of 1 (latest)
I don’t think an example code snippet is necessary since it’s a very simple project
What number do you compare against to determine you're missing 1-2k?
I log guild.members.cache.size before and after fetch is finished
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
Those bots all utilize the approximate count as that's all they can do without having a bot user in the guild. Your count on cache is exact
Guild#approximateMemberCount [email protected]
The approximate amount of members the guild has You will need to fetch the guild using fetch if you want to receive this parameter
I’m sure and I always will be that not all the members are in the cache
I always had troubles
When some members aren’t in cache when I get them
Can you clarify what you mean by that? Get them where/how?
Yeah I’ll write it from phone
new Client({ intents: GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers })
guild.members.cache.get(id)
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
How do you make sure you only .cache.get() after the initial fetch fully resolved?
Fetching 320k members will take some time
Because initial fetch is fully resolved in like 3 seconds
And nothing happens within 3 seconds of bot start
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
Yeah but I just can’t think of way to prove this or find a representation
Okay so why when I restart bot it logs 318592, then I restart it again and it shows 315122 and I restart it again 320009
its so random
Try this (the reply chain). The scales are entirely different between our servers, but this helped in my case.
#djs-help-v14 message
I'm trying to help you here. Which is why I asked what you tried to narrow your issue, how you made sure the fetch resolved fully, etc. I won't be able to help you if you neither show the code how you do it nor tell me how you do it
And I understand that you want to help me but I provided you everything you needed
.
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?
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
this is already what we could assume based on your previous messages, so this doesn't change the situation that much
What else do you need because that is whole code
Literally PLAIN whole code one index.js file
that does not look like a code though
Discord bot application is brand new
How it doesn’t 😭
it just says what you think could be happening when the code is running
Now you're just trolling us. Stop it
No. we want code, is that so hard to understand?
No, it says that I’m debugging cached members size every time I fetch them and they’re always different (i see it with my eyes I’m not just imagining it)
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
~~Okay, I think I found the reason for that behavior: https://discord.com/developers/docs/events/gateway-events#request-guild-members~~ nvm, still searching
well i can think of like
maybe at the moment when I fetch members
some of them are unavailable like in discord
but that doesnt make a lot of sense
Nah, I got another theory at the moment, but need to verify internally first
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?
okay sure, and just for confirmation it should be setTimeout and not setInterval ?
Yes, just should wait a bit after the fetch call before logging those
alr will send result asap
228970 228971
after 2nd restart 228522 228522
whole fetch is finished very fast like few seconds
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
thats in guild with 228k
So the numbers could actually be correct then?
this was correct
this isnt
when i said this, i said it because i had same thing in that guild too
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
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
i see
Does either of those bots have GuildPresences intent? Either by being in less than 100 guilds or by being approved for it?