【问题标题】:An error is issued when opening the telebot keyboard打开遥控机器人键盘时出现错误
【发布时间】:2021-12-23 17:47:53
【问题描述】:

有这样一段代码,改变信息后打开键盘,但执行时报错。

elif (merchant_id == 2):
                bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text='Your request was accepted', parse_mode="Markdown", reply_markup=keyboard.main_keyboard())

错误:

对 Telegram API 的请求不成功。错误代码:400。说明:错误请求:需要内联键盘

但是当执行另一部分代码时,键盘会立即打开。这是键盘代码:

def main_keyboard():
markup = types.ReplyKeyboardMarkup(one_time_keyboard = False, resize_keyboard = True)
btn1 = types.KeyboardButton('Hello')
btn2 = types.KeyboardButton('Start')
btn3 = types.KeyboardButton('Add')
btn4 = types.KeyboardButton('Stop')
markup.add(btn1, btn3)
markup.add(btn2)
markup.add(btn4)
return markup

如何解决问题,使键盘在代码的两个部分都正确打开? 也许有必要更换或添加一些功能。

【问题讨论】:

    标签: python api telegram telegram-bot py-telegram-bot-api


    【解决方案1】:

    main_keyboard 返回一个ReplyKeyboardMarkup,但reply_markup 参数edit_message_text 只接受InlineKeyboardMarkup 对象,如official API docs 中所述。在"updating messages" paragraph 的标题中说:

    请注意,目前只能在没有回复标记或使用内联键盘的情况下编辑消息。

    【讨论】:

      猜你喜欢
      • 2019-09-15
      • 2019-08-14
      • 2017-01-25
      • 2019-06-04
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 2020-12-04
      • 2015-04-05
      相关资源
      最近更新 更多