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.
No description
21 Replies
d.js toolkit
d.js toolkit14mo ago
- 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 OP
SpecialSauce
SpecialSauce14mo ago
You 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.
Ali
AliOP14mo ago
I got role from cache too And it had no member object defined
SpecialSauce
SpecialSauce14mo ago
Were the members cached?
Ali
AliOP14mo ago
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
SpecialSauce
SpecialSauce14mo ago
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.
Ali
AliOP14mo ago
Oh I got the issue now How can I manually cache members
SpecialSauce
SpecialSauce14mo ago
You can use the guild member manager and call fetch() <Guild>.members.fetch()
Ali
AliOP14mo ago
I see Guide me on this
d.js docs
d.js docs14mo ago
method GuildMemberManager#fetch() Fetches member(s) from a guild.
Ali
AliOP14mo ago
I want to cache admin members of a server It wouldn't be good to cache all members
SpecialSauce
SpecialSauce14mo ago
Depends on the size of the guild.
Ali
AliOP14mo ago
Yeah exactly But it will grow I just want members of a role to be cached
SpecialSauce
SpecialSauce14mo ago
There isn’t an endpoint that returns only members that have a certain role.
Ali
AliOP14mo ago
I see So like I could create a slash conmand Empty one That can cache it automatically Is this good way
SpecialSauce
SpecialSauce14mo ago
Not sure what you mean.
Ali
AliOP14mo ago
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?
SpecialSauce
SpecialSauce14mo ago
If the member uses the command they would end up cached.
Ali
AliOP14mo ago
And after how much time do we need to recache member Or is it forever until the instance of client gets closed
SpecialSauce
SpecialSauce14mo ago
Depends on how the client is constructed. The cache is cleared after it reaches a certain size I believe.
Ali
AliOP14mo ago
I see Thank you very much Lol you saved my screen ig I was about to punch it have a deadline for project
Want results from more Discord servers?
Add your server