Как получить сообщение об ошибке от @ commands.has_role () - PullRequest
1 голос
/ 13 июня 2019

Я недавно создал бот-диск, используя discord.py. Я попытался сделать разрешения для некоторых команд. У меня есть эта функция команды теста:

@client.command()
@commands.has_role('Moderator')
async def cool(ctx):
    await ctx.send("You are cool indeed!")

Как я могу вернуть сообщение (ошибку), если у пользователя нет роли «Модератор»?

Я уже пробовал это:

async def on_command_error(ctx, error):
    if isinstance(error, commands.NoPrivateMessage):
        await ctx.send("*Private messages.* ")
    elif isinstance(error, commands.MissingRequiredArgument):
        await ctx.send("*Command is missing an argument:* ")
    elif isinstance(error, commands.DisabledCommand):
        await ctx.send("*This command is currenlty disabled. Please try again later.* ")
    elif isinstance(error, commands.CheckFailure):
        await ctx.send("*You do not have the permissions to do this.* ")
    elif isinstance(error, commands.CommandNotFound):
        await ctx.send("*This command is not listed in my dictionary.*")

Но я ничего не получу от этого.

1 Ответ

0 голосов
/ 13 июня 2019

В функции on_command_error проверьте значение commands.MissingRole или commands.MissingAnyRole.

if isinstance(error, (commands.MissingRole, commands.MissingAnyRole)):
    ...
...