Get all users who have a role
I'm trying to get a list of User IDs for everyone in a server who has a particular role. Here is my code.
Camps is a json file
33 Replies
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
You can use
role.members
for this, it does this filtering for you, but you first need to fully populate the guild member cache using guild.members.fetch
I don't understand
Is
guild.members.fetch
the whole line of code or is it a variable I then have to keep using?
@monbreyYou can just call it,
await guild.members.fetch()
and that will populate guild.members
That way when you access role.members
it can correctly filter all of themThanks
When doing this I get this error
Cannot read properties of undefined (reading 'members')
Oh sorry, probably
message.guild
in this contextNow I'm just getting Message not defined
Here's more of my code and my error
@monbrey
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Your original example used message so I assumed, my bad
I was trying various methods and none worked.
I've sorted part of it but it still isn't recognising the members of the roles
This should work if you just swap the two
message
with interaction
Code
Error
I did
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
From JSON
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Ah
ok
Nope, maybe not
Same issue
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
it's the role ID. I didn't want to share it so I replaced it with the word when I copied and pasted here. It's now a string with the Role ID
it needs to be a string
ids arent really sensitive, can you show it to us?
"Bootcamper": "1031273912450953281",
That looks correct
if it had been broken as a number format it usually ends in 00
How did you get that value?
Copied from Discord
Where in Discord, the roles menu?
Right clicked the role in the roles menu
Yeah should be fine then
Still not working
@monbrey
whats the current error? members of undefined?
here?
yes
Can you show your intents?
Just GuildMembers
Add Guilds
Ah finally
Thanks so much
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View