Guild Member cache doesn't contain all users
Hey, I'm not too sure why but when I check the member cache of a specific guild, I can only see 1 user (My bot account itself) but not other users.
My guild has two users in it, one is the bot and one is myself
The discord account has access to view the members because I use this same bot account to do this in another script I run.
My intents also match the working bot script I have:
12 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- 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!Discord does not guarantee you all members in the initial guild data.
You might (read: probably always) need to fetch them manually, if you care about having them all synced.
You can do so through
GuildMemberManager#fetch
.If I understand correctly, I can fetch() to get all users, then the cache should be up to date enough that I can trust it to contain all the data present at the time of the fetch?
Yeah, it should stay updated, fetching again will short-circuit though (as all members are cached).
It throws an error if there's nothing new fetched?
No, it will just resolve if all members are fetched.
Ah okay
Thanks I'll give it a go
Looks like the behaviour changed (probably with v14) and it will no longer short-circuit.
Hmm now I have a new issue
After doing a fetch, my cache contains two users. But both of them are the bot itself and it still doesn't contain my user
should have different keys though, as otherwise you'd only have one member.
This seems odd.
Can you try it in a minimal and clean environment?
So no other dependencies aside from
discord.js
and just the code to start the bot and fetch members along with logging stuff.Sorry... False alarm 😅
I don't even want to explain how I managed to confuse that
Looks like it's all working, thanks
That's good to hear