N
N
NeoLight32020-07-31 15:22:03
Python
NeoLight3, 2020-07-31 15:22:03

How to make a user check for a role when calling a command in discord?

I'm making a discord bot in Python and I want to check the role of the User,
For example, if the User does not have the "Admin" role, then the bot will display the message "You are not allowed to use this command"
And if there is, then execute.

How can this be checked?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-07-31
@NeoLight3

role = discord.utils.find(lambda r: r.name == 'Admin', 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 question

Ask a Question

731 491 924 answers to any question