Search code examples
pythondiscord.pyrolesmember

How to check member role?


How I can get a member role, for use it in match/case purposes

@client.event
async def on_voice_state_update(member, before, after):
    person_role = ? ? ?
    match person_role:
        case "User 1":
            pass
        case "User 2":
            pass
        case _:
            pass

From users roles depend what channel name set when new voice channel will be create.


Solution

  • If you're just trying to get the roles of a member use member.roles which will return a list of type discord.Role. To find a certain role in that list, first get the role using either the name:

    role = discord.utils.get(member.guild.roles, name="FunRole")
    

    or the ID:

    role = discord.utils.get(member.guild.roles, id=41153483483138)
    

    Then see if the role is in the members list of roles:

    if role in member.roles:
        print("They have this role.")