我的电报机器人遇到了难题。我试图在单击嵌套菜单选择时提示响应。但是,它提示错误:“邮件未修改:指定的新邮件内容和回复标记与邮件的当前内容和回复标记完全相同”
触发响应时是否错过了某些内容?还是新事物,所以请原谅新手问题
def start(update, context):
update.message.reply_text(main_menu_message(),
reply_markup=main_menu_keyboard())
def main_menu(update,context):
query = update.callback_query
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text=main_menu_message(),
reply_markup=main_menu_keyboard())
def first_menu(update, context):
query = update.callback_query
# print(context.match)
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text=first_menu_message(),
reply_markup=first_menu_keyboard())
# and so on for every callback_data option
def first_submenu(update):
update.message.reply_text("Use /start to test this bot.")
################ Keyboard #######################
def main_menu_keyboard():
keyboard = [[InlineKeyboardButton("Exercise", callback_data='m1'),
InlineKeyboardButton("Option 2", callback_data='m2')],
[InlineKeyboardButton("Option 3", callback_data='m3')]]
return InlineKeyboardMarkup(keyboard)
def first_menu_keyboard():
keyboard = [[InlineKeyboardButton('Running', callback_data='m1_1')],
[InlineKeyboardButton('Push Ups', callback_data='m1_2')],
[InlineKeyboardButton('Back', callback_data='main')]]
return InlineKeyboardMarkup(keyboard)
####### Messages ############
def main_menu_message():
return 'Choose the option:'
def first_menu_message():
return 'Select exercise:'
def main():
updater.dispatcher.add_handler(CommandHandler('start', start))
updater.dispatcher.add_handler(CallbackQueryHandler(main_menu, pattern='main'))
updater.dispatcher.add_handler(CallbackQueryHandler(first_menu, pattern='m1'))
updater.dispatcher.add_handler(CallbackQueryHandler(first_submenu, pattern='m1_1'))
updater.start_polling()
updater.idle()
if __name__ == '__main__':
updater = Updater(TOKEN, use_context=True)
main()
我当前的堆栈跟踪状态:
Traceback (most recent call last):
File "Python\Python37-32\lib\site-packages\telegram\ext\dispatcher.py", line 390, in process_update
handler.handle_update(update, self, check, context)
File "Python\Python37-32\lib\site-packages\telegram\ext\handler.py", line 117, in handle_update
return self.callback(update, context)
File "PycharmProjects/project/app.py", line 32, in first_menu
reply_markup=first_menu_keyboard())
File "<decorator-gen-27>", line 2, in edit_message_text
File "Python\Python37-32\lib\site-packages\telegram\bot.py", line 67, in decorator
result = func(*args, **kwargs)
File "Python\Python37-32\lib\site-packages\telegram\bot.py", line 1834, in edit_message_text
return self._message(url, data, timeout=timeout, reply_markup=reply_markup, **kwargs)
File "Python\Python37-32\lib\site-packages\telegram\bot.py", line 172, in _message
result = self._request.post(url, data, timeout=timeout)
File "Python\Python37-32\lib\site-packages\telegram\utils\request.py", line 334, in post
**urlopen_kwargs)
File "Python\Python37-32\lib\site-packages\telegram\utils\request.py", line 245, in _request_wrapper
raise BadRequest(message)
telegram.error.BadRequest: Message is not modified: specified new message content and reply markup are exactly the same as a current content and reply markup of the message'
答案 0 :(得分:0)
似乎Telegram Api尚未为此做好准备。他们还在the docs.
中对此进行了撰写请注意,当前只能在不使用reply_markup或嵌入式键盘的情况下编辑邮件。