role.members returns undefined
This property was working fine but then suddenly it stopped working. i am using fetch command to load role using id.
21 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 OPYou don’t need to fetch the role if you have the guilds intent. <Role>.members only returns cached members with that role.
You could fetch the members from the guild first if you want them cached.
I got role from cache too
And it had no member object defined
Were the members cached?
Idk I am new to discord js
Do we have to cache them first?
It was working fine until now I didn't explicitly cache anything
Members don’t auto cache like channels and roles. Members become cached if they trigger events that return the full member object from the api.
Oh
I got the issue now
How can I manually cache members
You can use the guild member manager and call fetch()
<Guild>.members.fetch()
I see
Guide me on this
I want to cache admin members of a server
It wouldn't be good to cache all members
Depends on the size of the guild.
Yeah exactly
But it will grow
I just want members of a role to be cached
There isn’t an endpoint that returns only members that have a certain role.
I see
So like I could create a slash conmand
Empty one
That can cache it automatically
Is this good way
Not sure what you mean.
So you say
When an interaction is created
The member gets catched
Cached
Slash command is an interaction and it would cache the member? No?
If the member uses the command they would end up cached.
And after how much time do we need to recache member
Or is it forever until the instance of client gets closed
Depends on how the client is constructed. The cache is cleared after it reaches a certain size I believe.
I see
Thank you very much
Lol you saved my screen ig
I was about to punch it have a deadline for project