Skip to content
This repository has been archived by the owner on Mar 25, 2020. It is now read-only.

How to get a list of users that have the same role. #298

Open
munio76 opened this issue Oct 16, 2018 · 2 comments
Open

How to get a list of users that have the same role. #298

munio76 opened this issue Oct 16, 2018 · 2 comments

Comments

@munio76
Copy link

munio76 commented Oct 16, 2018

Hi, and first of all thank you for this great client!
I've read the documentation at https://izy521.github.io/discord.io-docs/Discord.Client.html, but since I'm not a developer I don't know how to figure out this:
in my discord server I have 8 roles, correspondig to "levels" in a game; I need my bot to list all users/members with one of the roles.
Could you kindly give me a hint?
Thank you.

@Peacerekam
Copy link

Peacerekam commented Oct 16, 2018

Object.values(bot.servers[event.d.guild_id].members)
   .filter(m => m.roles.includes('246666176464158721'))
   .map(m => m.username + "#" + m.discriminator)

will return array like this:

["Madokami#6496","MimeeDevBot#6944","Charlemagne#3214","PatchBot#0303"]

how it works:

bot.servers[event.d.guild_id].members has all members of our guild
member.roles is an array of role IDs that the user has
Object.values() is there to enable a .filter() (and .map()) function
we use .filter() to get only the objects that have have a role with ID 246666176464158721, we use .includes() on an array for that
at the end to make it "readable" i included an extra .map() function that will output only the username#discriminator rather than the whole member object

that's probably the easiest approach

@munio76
Copy link
Author

munio76 commented Oct 16, 2018

Thank you for your reply, I'll try it asap!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants