S
S
Shandy2021-02-04 14:53:15
Python
Shandy, 2021-02-04 14:53:15

How to make a blacklist for teams?

There is a table in the database where participants who are prohibited from using commands will be stored. I did this:

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

And it works, the bot does not respond to the commands of people from the list, but this is displayed in the console:
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.

How would you fix this? And yes, I know that you can check the user in the command itself, but I would like it that way.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander, 2021-02-04
@MrShandy

https://stackoverflow.com/questions/63127079/disco...

A
Astrohas, 2017-08-10
@devhub16

error in my opinion here
Replace with
WHERE id IN({$num_contact})

M
Mountaineer, 2017-08-10
@Mountaineer

I advise:
1. Arrange the arms for AND, OR.
2. Comment parts of the query to find the problematic condition

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question