Closed
Description
Checklist
- I am sure the error is coming from aiogram code
- I have searched in the issue tracker for similar bug reports, including closed ones
Operating system
Windows 10
Python version
3.10
aiogram version
3.0.0rc1
Expected behavior
When the command "/admin" is sent to the bot, the filter AdminFilter should identify whether the text "admin" is present in the message. If it is, the is_admin variable should be passed to the admin_command_handler, allowing it to execute its logic.
Current behavior
The variable is_admin is not being passed to the admin_command_handler, resulting in an error indicating that the variable is not defined.
Steps to reproduce
- Replace "YOUR_TOKEN_HERE" with your bot token in the code snippet.
- Run the code.
- Send the "/admin" command to the bot.
- Observe the error indicating that the variable is_admin is not defined.
Code example
import asyncio
import logging
import sys
from aiogram import Bot, Dispatcher, Router
from aiogram.filters import BaseFilter, Command
dp = Dispatcher()
token = "YOUR_TOKEN_HERE"
bot = Bot(token)
class IsAdmins(BaseFilter):
async def __call__(self, message):
if "admin" in message.text.casefold():
return {"is_admin": True}
return False
async def admin_command_handler(message, is_admin: bool):
await message.answer(f"Admin Command Handler, is_admin: {is_admin}")
admin_router = Router()
admin_router.message.filter(IsAdmins())
admin_command_router = Router()
admin_router.include_router(admin_command_router)
dp.include_router(admin_router)
admin_command_router.message.register(adm_com_router, Command("admin"))
async def main():
await dp.start_polling(bot)
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
asyncio.run(main())
Logs
No response
Additional information
No response