How can I check if a user has a role

Viewed 28

Currently, I'm using @commands.has_role("rolename"), but I can't figure out how to use if or something similar to check if the user has the role. If they do, run the command as normal, and if not send a message like "No Permission!"

Can anyone help me?

1 Answers

here is an example snippet hope it helps, Admin is the role on the code below:

  @bot.command(pass_context=True)
    @commands.has_role("Admin")
    async def unmute(ctx, user: discord.Member):
        role = discord.utils.find(lambda r: r.name == 'Member', ctx.message.guild.roles)
        if role in user.roles:
        await bot.say("{} is not muted".format(user))"JUST A TEXT TO SEE THE HIT"
        "RUN OPERATION WITHIN THE CONTEXT"
        else:
        await ctx.send("No permissions.")
Related