Scripteer
@Scripteer
Веб дизайнер, интересуюсь python, знаю html,css +-

Как сделать использование команды по роли?

Если знаете как делать ботов в дискорд, то знаете команду @commands.has_permissions( administrator = True)
Она делает так что бы команду смог исполнять только админ, но как сделать что бы и другая роль, например модер смог тоже ее использовать?
  • Вопрос задан
  • 264 просмотра
Решения вопроса 1
@GeneD88
QA
@commands.has_any_role

discord.ext.commands.has_any_role(*items)
A check() that is added that checks if the member invoking the command has any of the roles specified. This means that if they have one out of the three roles specified, then this check will return True.

Similar to has_role(), the names or IDs passed in must be exact.

This check raises one of two special exceptions, MissingAnyRole if the user is missing all roles, or NoPrivateMessage if it is used in a private message. Both inherit from CheckFailure.

Changed in version 1.1: Raise MissingAnyRole or NoPrivateMessage instead of generic CheckFailure

Parameters
items (List[Union[str, int]]) – An argument list of names or IDs to check that the member has roles wise.

Example

content_copy
@bot.command()
@commands.has_any_role('Library Devs', 'Moderators', 492212595072434186)
async def cool(ctx):
await ctx.send('You are cool indeed')
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы