Answer the question
In order to leave comments, you need to log in
How to check if a user has a role?
Hello. How can I check if a Discord user has a role? I want to make a special role so that the bot executes commands only for those users who have this role, for example "Admin". And if there is no role, he wrote that they need such and such a role. I don't know much about Python, the discord.py library
Answer the question
In order to leave comments, you need to log in
@bot.command(pass_context=True)
@commands.has_role("Admin")
async def check(ctx, user: discord.Member):
role = discord.utils.find(lambda r: r.name == 'название_роли', ctx.message.server.roles)
if role in user.roles:
await bot.say("у вас есть роль")
else:
await bot.say("у вас нету роли")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question