How to pass Bot instance into middleware? #1478
-
Hello, how can I pass a bot object in My goal is to write a Subscription Checker class CheckSubscriptionMiddleware(BaseMiddleware):
async def __call__(self, handler: Callable[[types.Message, Dict[str, Any]], Awaitable[Any]], event: types.Message,
data: Dict[str, Any]) -> Any:
user = await bot.get_chat_member(chat_id="example", user_id=event.from_user.id)
if user.status == 'left':
return await event.reply("You are not subscribed")
await handler(event, data) |
Beta Was this translation helpful? Give feedback.
Answered by
JrooTJunior
May 5, 2024
Replies: 1 comment
-
Bot instance is available in the context data: bot = data["bot"] |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
sdmway
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bot instance is available in the context data: