I have no idea how to fix it
I try this:
@Router.message(F.text == "/start")
async def send_welcome(message: types.Message, state: FSMContext):
await state.set_state(UserState.awaiting_function) # встановлюємо стан
await message.reply("Hi!\nI'm EchoBot!\nPowered by aiogram.")
And this:
@dp.message(lambda message: message.text.lower() == '/start', state = FSMContext)
async def send_welcome(message: types.Message):
await state.set_state(UserState.awaiting_function)
""" Greets the user and introduces the bot """
await message.reply("Hi!\nI'm EchoBot!\nPowered by aiogram.")
Thats an error:
Traceback (most recent call last):
File "C:\Users\USER\PycharmProjects\PythonProject\bot_main\main.py", line 26, in <module>
@Router.message(FSMContext.text == "/start")
^^^^^^^^^^^^^^
AttributeError: type object 'Router' has no attribute 'message'
Someone can help me?`
1 Answer 1
I suppose the router is imported from aiogram and as per the docs that is not the right way to use it as you should create an instance of the Router
https://docs.aiogram.dev/en/dev-3.x/dispatcher/router.html
your code would look like this
from aiogram import Router
# your other imports
my_router = Router(name=__name__) # --> you have to create an instance of the router not use it directly
@my_router.message() # pass your parameters here F.text == "/start"
async def send_welcome(message: types.Message, state: FSMContext):
await state.set_state(UserState.awaiting_function) # встановлюємо стан
await message.reply("Hi!\nI'm EchoBot!\nPowered by aiogram.")
answered Sep 22, 2025 at 21:22
Olsi Hoxha
4593 silver badges13 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py