Search code examples
pythonaiogram

TypeError: answer() got an unexpected keyword argument reply_markup


My code is:

@dp.callback_query_handler(text='add word')
async def add_word(message: Message):

    keyboard = all_dictionaries_keyboard()
    await message.answer('Please choose dictionary at which words will be added:',
                         reply_markup=keyboard)
    await AddWords.get_dictionary.set()

Why does answer() says unexpected argument here but worked everywhere else?

I don't think this will give any more info but here is full traceback:

sarabot_1  | Traceback (most recent call last):
sarabot_1  |   File "/usr/local/lib/python3.9/site-packages/aiogram/dispatcher/dispatcher.py", line 414, in _process_polling_updates
sarabot_1  |     for responses in itertools.chain.from_iterable(await self.process_updates(updates, fast)):
sarabot_1  |   File "/usr/local/lib/python3.9/site-packages/aiogram/dispatcher/dispatcher.py", line 236, in process_updates
sarabot_1  |     return await asyncio.gather(*tasks)
sarabot_1  |   File "/usr/local/lib/python3.9/site-packages/aiogram/dispatcher/handler.py", line 116, in notify
sarabot_1  |     response = await handler_obj.handler(*args, **partial_data)
sarabot_1  |   File "/usr/local/lib/python3.9/site-packages/aiogram/dispatcher/dispatcher.py", line 284, in process_update
sarabot_1  |     return await self.callback_query_handlers.notify(update.callback_query)
sarabot_1  |   File "/usr/local/lib/python3.9/site-packages/aiogram/dispatcher/handler.py", line 116, in notify
sarabot_1  |     response = await handler_obj.handler(*args, **partial_data)
sarabot_1  |   File "/home/sarabot/handlers.py", line 34, in add_word
sarabot_1  |     await message.answer('Please choose dictionary at which words will be added:',
sarabot_1  | TypeError: answer() got an unexpected keyword argument 'reply_markup'```


Solution

  • So the solution was to use Reply Keyboard instead.

    Despite the fact that telegram bots will always have a message from user (user needs to send /start command in order to use bot) if you use Inline Keyboard as first action by user and then try to read callback you will get this error because aiogram won't see a message from user. Even command /menu that was sent by user in my case.