Wrote my first middleware to check if a user is logged in, the middleware doesn’t want to work at all.
Python code:
class CheckUserExist(BaseMiddleware):
async def call(
self,
handler: Callable[[Message, Dict[str, Any]], Awaitable[Any]],
event: Message,
data: Dict[str, Any]
) -> Any:
user = data[‘event_from_user’]
print(user)
user_id = user.id
print(‘Base’)
If not await check_user_exist(user_id):
await event.answer('You are not registered. Please register using the /start command.")
else:
return await handler(event, data)
And I connect it this way
Python code:
router.message.middleware(user_check.CheckUserExist())
I am using aiogram 3.10, python 3.10 too
I’ve tried both with dispatcher and router, but either the bot goes on a binge and doesn’t respond at all or nothing there but middleware.
Vladdra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.