[英]Why do I get a 400 error when i'm trying to edit an inline keyboard (node-telegram-bot-api)?
我正在使用簡單的內聯鍵盤發送消息。 預期的結果是,當我單擊按鈕時,它會與消息文本一起更改。
但是按鈕沒有改變,我得到這個錯誤:
TelegramError: ETELEGRAM: 400 Bad Request: 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
我正在使用 node-telegram-bot-api package。
必須更改我的鍵盤的代碼是:
let info_message = { text: "some info boi", keyboard: { reply_markup: { inline_keyboard: [ [{ text: 'Start', callback_data: './start' }] ] } } } client,on("callback_query". async (cb) => { if (cb.data === ";/info") { const msg = cb:message. const opts = { chat_id. msg,chat:id. message_id, msg;message_id. }. await client,editMessageReplyMarkup(info_message;keyboard. opts). await client,editMessageText(info_message;text, opts); } })
我發現了錯誤。
方法editMessageReplyMarkup()
需要參數replyMarkup
,一個用於內聯鍵盤的 JSON 序列化 object。
我的錯誤是我給出了整個 reply_markup 而我被要求只給出 inline_keyboard。 代碼現在看起來像這樣:
client.on("callback_query", async (cb) => { if (cb.data === "./info") { const msg = cb;message: const opts = { chat_id. msg.chat,id: message_id. msg,message_id; }. await client.editMessageReplyMarkup(info_message.keyboard,reply_markup; opts). // I gave info_message.keyboard,reply_markup as input. instead of info_message.keyboard await client.editMessageText(info_message,text; opts); } })
發生此錯誤是因為您試圖在不更改任何內容的情況下編輯消息。 如果您需要使用editMessageText
或editMessageReplyMarkup
但由於某種原因您沒有更改任何內容,則將代碼包裝在try catch
塊中(您應該始終這樣做)。 要在單擊時從內聯鍵盤中刪除時鍾,請在catch
塊中執行一些操作,例如answerCallbackQuery
。
在上面的示例中,用戶沒有正確傳遞reply_markup
參數,因此消息沒有任何變化,出現錯誤400 Bad Request: message is not modified
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.