bot.py
import asyncio
from aiogram import Bot, Dispatcher
from handlers import user_commands
from config import TOKEN
async def main():
bot = Bot(TOKEN, parse_mode="HTML")
dp = Dispatcher()
dp.include_router(
user_commands.router,
)
await dp.start_polling(bot)
if __name__ == "__main__":
asyncio.run(main())
user_commands.py
from aiogram import Router
from aiogram.types import Message
from aiogram.filters import CommandStart, Command
from data.users import add_db, get_me
router = Router()
@router.message(CommandStart())
async def start(message: Message):
await message.answer("Hello")
await add_db(message)
@router.message(Command('me'))
async def get_me(message: Message):
await get_me(message)
users.py
from motor.motor_asyncio import AsyncIOMotorClient
from aiogram.types import Message
from aiogram.filters import CommandStart, Command
from config import MONGO_DB
from aiogram import Router
cluster = AsyncIOMotorClient(MONGO_DB)
collection = cluster.test.users
@router.message()
async def get_me(message: Message):
user_id = message.from_user.id
data = await collection.find_one({"_id": user_id})
await message.answer(data)
Команда /start работает нормально, а вот с /me проблемы:
RecursionError: maximum recursion depth exceeded