python - 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'```
解决方案
所以解决方案是改用回复键盘。
尽管电报机器人总是会收到来自用户的消息(用户需要发送 /start 命令才能使用机器人),但如果您使用内联键盘作为用户的第一个操作,然后尝试读取回调,您将收到此错误,因为 aiogram不会看到来自用户的消息。在我的情况下,甚至是用户发送的命令 /menu 。
推荐阅读
- tesseract - 将 .traineddata 与 passportEye Python 一起用于 MRZ
- python - 如何根据特定条件转换和创建具有 0 和 1 的 pandas 列
- visual-studio-2017 - 无法将提交推送到分支
- python - 如何在pyqt5 Python中的行编辑中添加背景文本
- firebase - 在 Flutter 中以表格形式查看 FIrestore 数据
- angular - 星云组件无法正确呈现
- android - 将信息传递给暂停的活动以调用方法(不是 UI 更新)
- haskell - 如何在haskell中正确解决帕斯卡三角形?
- javascript - 在特定页面上单击浏览器后退按钮后如何重定向到主页
- php - PHP 中的 AWS SES createTemplate