guild.members.fetch will still fetch those who have left the server
Hey everyone, I am trying to make a simple function that checks if a user is in a server.
The problem is that when a user leaves the server,
guild.members.fetch
does not seem to be up to date. It will return a member as if they were still in the server.
But it does work fine the other way around, if the client is already initialized and a player joins the server, it will be up to date with the fact that they joined. It just doesn't seem to work someone leaves the server.
It will throw an error however if the client was initialized while the user was not in the server, which is good. It just can't tell who leaves the server during runtime.
Is this normal behavior? Is there a way to make it so guild.members.fetch will always be accurate?9 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!
- ✅
Marked as resolved by OPWhat intents and partials do you have enabled?
hello, here are my intents, i do not know what partials means
ah, you don't have the
GuildMembers
intent
you won't receive guild member events, hence why your members cache is out of date
I don't remember the behavior of fetch()
without the GuildMembers
intent, but I'm pretty sure that method won't work unless you have the intent enabledthank you, i will test it out when i can. its a bit weird, because it actually seems to work at least a little bit without the guild members intent
You're able to fetch members individually, and any event you receive that has a
member
object will update the guild member in cache
most notably, your GuildMessages
intent is letting you receive message create events, which contains a partial member objectthanks you're a big help
@Qjuh can you tell me how to do that?
you can also just add the intent and your cache won't be unreliable anymore
at least not in terms of members leaving/joining
oh, forgot it was privileged