Answer the question
In order to leave comments, you need to log in
How to continue receiving aiogram messages?
When blocking a user, I want the bot to completely ignore them. I thought a good solution would be the code
@dp.message_handler(content_types=["text"])
async def check_ban(message: types.Message):
if is_banned(message.from_user.id):
return
Answer the question
In order to leave comments, you need to log in
It is a bad idea! The library selects the first handler that matches the condition (in this case, content_types=["text"]) and does not use the rest at all.
I recommend either inserting a check into each handler, or making it a condition in the decorator:
@dp.message_handler(lambda message: not is_banned(message.from_user.id)
What does "no further" mean? Is this handler at the very top of the code? If so, it will catch all text messages, including messages that are just commands. So any text processors below it will not work.
If you want to do such a check, I would make my own filter, which I put in the handler. In the filter already check the user
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question