MrShandy
@MrShandy
Python

Как сделать черный список для команд?

Есть таблица в бд, где будут храниться участники, которым запрещено использовать команды. Я сделал это:
def member_not_blacklisted(ctx):
    with con:
        cur = con.cursor()
        cur.execute("SELECT user_id FROM client_bot.blacklist;")
        rows = cur.fetchall()
        value = True
        for row in rows:
            if ctx.message.author.id == int(row[0]):
                value = False
                break
    return value

@bot.command(aliases=['билет'])
@commands.check(member_not_blacklisted)
@commands.cooldown(1,600,discord.ext.commands.BucketType.user)
async def movie_ticket(ctx):
    # код

@movie_ticket.error
async def movie_ticket_error(ctx, error):
    if isinstance(error, commands.CommandOnCooldown):
        time_m = (round(error.retry_after)//60)%60
        time_s = round(error.retry_after)%60
        await ctx.send(f'Эй! {ctx.author.mention}, подожди еще {time_m} минут {time_s} секунд', delete_after=10)
    else:
        raise error

И это работает, бот не реагирует на команды людей из списка, но в консоль выводится это:
Traceback (most recent call last):
  File "C:\Users\MrSha\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\MrSha\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\bot.py", line 942, in on_message
    await self.process_commands(message)
  File "C:\Users\MrSha\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\bot.py", line 939, in process_commands
    await self.invoke(ctx)
  File "C:\Users\MrSha\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\bot.py", line 906, in invoke
    await ctx.command.dispatch_error(ctx, exc)
  File "C:\Users\MrSha\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 424, in dispatch_error
    await injected(ctx, error)
  File "C:\Users\MrSha\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 71, in wrapped
    ret = await coro(*args, **kwargs)
  File "c:/Users/MrSha/Documents/GitHub/SG-client-bot/botv2.py", line 120, in movie_ticket_error
    raise error
  File "C:\Users\MrSha\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\bot.py", line 902, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\MrSha\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 856, in invoke
    await self.prepare(ctx)
  File "C:\Users\MrSha\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 779, in prepare
    raise CheckFailure('The check functions for command {0.qualified_name} failed.'.format(self))
discord.ext.commands.errors.CheckFailure: The check functions for command movie_ticket failed.

Как бы это пофиксить? И да, я знаю, что можно сделать проверку юзера именно в самой команде, но хотелось бы именно так.
  • Вопрос задан
  • 153 просмотра
Решения вопроса 1
Alexandre888
@Alexandre888 Куратор тега Боты
Javascript-разработчик
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

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

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