How to add role hierarchy in this command

so basically i want to add role hierarchy in this command i am using discord.py 2.0 i checked docs but i am not able to figure out how to exactly do it, pls help me i know its kina dumb question

@app_commands.command(name="ban", description="Ban A User")
    @app_commands.checks.has_permissions(ban_members=True)
    async def MC(self, interaction: discord.Interaction, user: discord.Member, reason: str) -> None:
        await interaction.response.defer(ephemeral=False, thinking=True)

        if reason == None:
            embed = discord.Embed(color=0x55a7f7, timestamp=datetime.datetime.utcnow())
            embed.set_footer(text="If you think this is unfair Join Our Ban appeal Server", icon_url=f"{interaction.user.avatar}")
            embed.add_field(name='Banned', value= f"{user} was Banned \n Reason :- **Not Provided** ") 
            await user.send(embed=embed)
            await user.ban()
            await interaction.followup.send(embed=embed)

1 answer

  • answered 2022-05-07 13:20 Eric Jin

    There exists a comparison to check role hierarchy. Members are ranked by their top role, which supports comparisons based on their index in the guild.

    if interaction.user.top_role <= user.top_role:
        # the person issuing the command is less than or equal to the person getting banned
        await interaction.followup.send('Hey, you are not allowed to do this.')
    # ban them
    
    

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum