R
R
RA4INA2021-06-29 21:17:32
Bots
RA4INA, 2021-06-29 21:17:32

How to set up a blacklist for a telegram bot?

There is a database with user ids that the bot should not respond to. Help connect this database to the bot, I can not find anywhere how to do it. I roughly understand how it should work, but something does not work. I would be very grateful if anyone can help with the code.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vindicar, 2021-06-29
@RA4INA

Option 1, simple: arrange the check as a function of the form user_id -> bool (true - blocked), call at the beginning of each command handler. If it returns true, then just return.
Option 1.5: I don't know about the cart, but the discord library allows you to specify a function for the command handler like "is it possible to call this handler?". Is there something similar for the library you are using?
Option 2: Design validation as a decorator, and decorate your handlers. Slightly shorter than option 1, if the reaction to the banned user is the same (for example, ignore), then I would prefer it.

V
Vasily Bannikov, 2021-06-29
@vabka

Just wrap the if. Like "if the message was sent from a user with an id that is contained in the database, then do not process"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question