Не могу найти в чем проблема. Ругается на отсутствие роутеров, хотя они есть

main.py

import asyncio
import logging
from aio_bot.config_reader import config
from aiogram import Bot, Dispatcher
from help_handlers.handlers import cmd_start, cmd_menu


async def main():
    logging.basicConfig(level=logging.INFO)
    bot = Bot(token=config.bot_token.get_secret_value(), parse_mode="HTML")
    dp = Dispatcher()
    dp.include_routers(cmd_start.handlers_router, cmd_menu.handlers_router)
    await bot.delete_webhook(drop_pending_updates=True)
    await dp.start_polling(bot)


if __name__ == "__main__":
    asyncio.run(main())

help_handlers\handlers.py

from datetime import datetime
from aio_bot.bot.keyboards.kbs import kbs_menu
from aiogram.filters import CommandObject, Command, CommandStart
from aiogram import types, F, html, Router

handlers_router = Router()


@handlers_router.message(CommandStart)
async def cmd_start(message: types.Message):
    time_now = datetime.now().strftime('%H:%M, %d-%m-%Y')
    kb = types.InlineKeyboardMarkup(inline_keyboard=kbs_menu())
    await message.answer(f"Привет!\nСейчас <b>{time_now}</b>\nВыбери, что будем делать:",
                         reply_markup=kb,
                         )


@handlers_router.callback_query(F.data == "menu")
async def cmd_menu(callback: types.CallbackQuery):
    time_now = datetime.now().strftime('%H:%M, %d-%m-%Y')
    kb = types.InlineKeyboardMarkup(inline_keyboard=kbs_menu())
    await callback.message.answer(f"Привет!\nСейчас <b>{time_now}</b>\nВыбери, что будем делать:",
                                  reply_markup=kb
                                  )

Ошибка:

Traceback (most recent call last):
  File "C:\Users\Egor Irvin\Desktop\Projects\aio_bot\bot\main.py", line 18, in <module>
    asyncio.run(main())
  File "C:\Users\Egor Irvin\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\Egor Irvin\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Egor Irvin\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\Egor Irvin\Desktop\Projects\aio_bot\bot\main.py", line 12, in main
dp.include_routers(cmd_start.handlers_router, cmd_menu.handlers_router)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'function' object has no attribute 'handlers_router'

Ответы (1 шт):

Автор решения: CausonQ

А для чего вы импортируете каждый хендлеров в отдельности?

Импорт будет таким:

import asyncio
import logging
from aio_bot.config_reader import config
from aiogram import Bot, Dispatcher
from handlers import help_handlers


async def main():
    logging.basicConfig(level=logging.INFO)
    bot = Bot(token=config.bot_token.get_secret_value(), parse_mode="HTML")
    dp = Dispatcher()
    dp.include_routers(help_handlers.handlers_router)
    await bot.delete_webhook(drop_pending_updates=True)
    await dp.start_polling(bot)


if __name__ == "__main__":
    asyncio.run(main())
→ Ссылка