Answer the question
In order to leave comments, you need to log in
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
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.
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 questionAsk a Question
731 491 924 answers to any question