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

Did you find this page helpful?