Search code examples
nextcord

NextCord - Get roles from slash command


I would like to make a command that checks what roles you have in NextCord.

Not permissions, but specifically roles. So that, if I have a role named "Giveaway" for example, I can make the command check if anyone who uses it has the role. If they do, they can start a giveaway but if not it will tell them they cannot start one.

Thank you!


Solution

  • https://docs.nextcord.dev/en/latest/ext/application_checks/index.html#nextcord.ext.application_checks.has_any_role

    from nextcord.ext import application_checks
    
    @bot.slash_command()
    @application_checks.has_any_role('Moderators', 492212595072434186)
    async def cool(interaction: Interaction):
        await interaction.response.send_message('You are cool indeed')
    

    Alternatively, you can check the users' roles in the callback by iterating over interaction.user.roles.