Is there a way to make a command that lists everybody who has a certain role in a discord server?

Viewed 86

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?

3 Answers

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.

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

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)
Related