Aiogram - Missing 1 required positional argument: callback()
@router.message(CommandStart())
@router.callback_query(F.data == 'main111')
async def cmd_start(message:Message,callback:CallbackQuery,):
await callback.message.edit_text(f'Welcome here! \n It is great to see ya, {message.from_user.first_name} ! \n Here is our rights! \n 1: \n 2: \n 3:', reply_markup=await kb.mainFunction())
await message.edit_text(f'Welcome here! \n It is great to see ya, {message.from_user.first_name} ! \n Here is our rights! \n 1: \n 2: \n 3:', reply_markup=await kb.mainFunction())
Пробовал без последней строки, но не работает
Ошибка:
File "C:\Users\Maks\Desktop\programming\pythonProject\MrPresidentVSCODE\.venv\Lib\site-packages\aiogram\dispatcher\dispatcher.py", line 309, in _process_update
response = await self.feed_update(bot, update, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Maks\Desktop\programming\pythonProject\MrPresidentVSCODE\.venv\Lib\site-packages\aiogram\dispatcher\dispatcher.py", line 158, in feed_update
response = await self.update.wrap_outer_middleware(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Maks\Desktop\programming\pythonProject\MrPresidentVSCODE\.venv\Lib\site-packages\aiogram\dispatcher\middlewares\error.py", line 25, in __call__
return await handler(event, data)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Maks\Desktop\programming\pythonProject\MrPresidentVSCODE\.venv\Lib\site-packages\aiogram\dispatcher\middlewares\user_context.py", line 49, in __call__
return await handler(event, data)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Maks\Desktop\programming\pythonProject\MrPresidentVSCODE\.venv\Lib\site-packages\aiogram\fsm\middleware.py", line 42, in __call__
return await handler(event, data)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Maks\Desktop\programming\pythonProject\MrPresidentVSCODE\.venv\Lib\site-packages\aiogram\dispatcher\event\telegram.py", line 121, in trigger
return await wrapped_inner(event, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Maks\Desktop\programming\pythonProject\MrPresidentVSCODE\.venv\Lib\site-packages\aiogram\dispatcher\event\handler.py", line 43, in call
return await wrapped()
^^^^^^^^^^^^^^^
File "C:\Users\Maks\Desktop\programming\pythonProject\MrPresidentVSCODE\.venv\Lib\site-packages\aiogram\dispatcher\dispatcher.py", line 276, in _listen_update
return await self.propagate_event(update_type=update_type, event=event, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Maks\Desktop\programming\pythonProject\MrPresidentVSCODE\.venv\Lib\site-packages\aiogram\dispatcher\router.py", line 142, in propagate_event
return await observer.wrap_outer_middleware(_wrapped, event=event, data=kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Maks\Desktop\programming\pythonProject\MrPresidentVSCODE\.venv\Lib\site-packages\aiogram\dispatcher\router.py", line 137, in _wrapped
return await self._propagate_event(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Maks\Desktop\programming\pythonProject\MrPresidentVSCODE\.venv\Lib\site-packages\aiogram\dispatcher\router.py", line 170, in _propagate_event
response = await router.propagate_event(update_type=update_type, event=event, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Maks\Desktop\programming\pythonProject\MrPresidentVSCODE\.venv\Lib\site-packages\aiogram\dispatcher\router.py", line 142, in propagate_event
return await observer.wrap_outer_middleware(_wrapped, event=event, data=kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Maks\Desktop\programming\pythonProject\MrPresidentVSCODE\.venv\Lib\site-packages\aiogram\dispatcher\router.py", line 137, in _wrapped
return await self._propagate_event(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Maks\Desktop\programming\pythonProject\MrPresidentVSCODE\.venv\Lib\site-packages\aiogram\dispatcher\router.py", line 162, in _propagate_event
response = await observer.trigger(event, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Maks\Desktop\programming\pythonProject\MrPresidentVSCODE\.venv\Lib\site-packages\aiogram\dispatcher\event\telegram.py", line 121, in trigger
return await wrapped_inner(event, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Maks\Desktop\programming\pythonProject\MrPresidentVSCODE\app\middleware.py", line 12, in __call__
result = await handler(event,data)#handler(обработчик)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Maks\Desktop\programming\pythonProject\MrPresidentVSCODE\.venv\Lib\site-packages\aiogram\dispatcher\event\handler.py", line 43, in call
return await wrapped()
^^^^^^^^^
TypeError: cmd_start() missing 1 required positional argument: 'callback'
Ответы (1 шт):
Автор решения: Mipsirint
→ Ссылка
В функции обработки колбэков в аргументах должен быть только callback
, без message
. В callback
и так хранится вся информация о сообщении, к которому была прикреплена кнопка
Ваш код должен выглядеть так:
@router.message(CommandStart())
@router.callback_query(F.data == 'main111')
async def cmd_start(callback: CallbackQuery):
await callback.message.edit_text(f'Welcome here! \n It is great to see ya, {callback.from_user.first_name} ! \n Here is our rights! \n 1: \n 2: \n 3:', reply_markup=await kb.mainFunction())