首页 > 解决方案 > TypeError: answer() 得到了一个意外的关键字参数 reply_markup

问题描述

我的代码是:

@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()

为什么 answer() 在这里说出乎意料的论点,但在其他任何地方都有效?

我认为这不会提供更多信息,但这里是完整的追溯:

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'```

标签: pythonaiogram

解决方案


所以解决方案是改用回复键盘。

尽管电报机器人总是会收到来自用户的消息(用户需要发送 /start 命令才能使用机器人),但如果您使用内联键盘作为用户的第一个操作,然后尝试读取回调,您将收到此错误,因为 aiogram不会看到来自用户的消息。在我的情况下,甚至是用户发送的命令 /menu 。


推荐阅读