2

I want to make a command that with a parameter of a role that lists everybody who has that role in a discord server. Is there a way to do this?

Jus18n
  • 29
  • 2

3 Answers3

4

You could just do something like this.

@client.command()
async def roles(ctx, *, role_wanted: discord.Role):
    for role in ctx.guild.roles:
        if role == role_wanted:
            for member in role.members:
                await ctx.send(member.name)

I've made this so the format is !roles @Role1 @Role2, etc you can have as many roles as you like in the list.

StarbuckBarista
  • 1,298
  • 1
  • 8
  • 20
0

If you can get the list of people, you can iterate through the list of players and use playerList[index].roles[index] == "Some Role"

Spidey Zac
  • 69
  • 1
  • 1
  • 10
  • Check this for more: https://stackoverflow.com/questions/54845875/how-do-i-check-if-a-user-has-a-specific-role-in-discord – Spidey Zac Sep 03 '20 at 17:10
  • And this: https://stackoverflow.com/questions/47733376/how-do-i-make-a-list-of-all-members-in-a-discord-server-using-discord-py – Spidey Zac Sep 03 '20 at 17:10
0

So this could be some code:

#Assuming this is in an on_message
x = message.guild.members
withTheRole = []
for member in x:
    if "ROLE" in member.roles:
        withTheRole.append(member.name)
StarbuckBarista
  • 1,298
  • 1
  • 8
  • 20
Spidey Zac
  • 69
  • 1
  • 1
  • 10