L
L
Lukas Tumas2020-06-09 23:16:08
Python
Lukas Tumas, 2020-06-09 23:16:08

How to check for a role?

Hello, how to check if the user who sent the message has a certain role.
For example, we enter the .role command and if this user has the desired role, then we display a message.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Nevzorov, 2020-06-19
@Lubitelok

You need to check for the presence of a role object :

@commands.command()
async def role(ctx):
    role = ctx.bot.get_role(719997201283022879)  # Получаем объект роли по ID
    if role in ctx.author.roles:
        await ctx.send("\N{WHITE HEAVY CHECK MARK}"}  # ✅
    else:
        await ctx.send("\N{CROSS MARK}")  # ❌

D
Dream, 2021-06-27
@dreameddd

You can use discord.utils.get

rolename = 719997201283022879
if discord.utils.get(member.roles, id=rolename):
    await ctx.send('Есть')
else:
    await ctx.send('Нету')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question