I am making a message with a simple inline keyboard. The expected result would be that when I click on the button it changes together with the message text.
However the button doesn’t change and i get this error:
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
I am using the node-telegram-bot-api package.
The code that has to change my keyboard is:
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);
}
})
2
Answers
I found out the error.
The method
editMessageReplyMarkup()
requires the parameterreplyMarkup
, A JSON-serialized object for an inline keyboard.My mistake was that I gave the whole reply_markup while I was requested to give only the inline_keyboard. The code now looks like this:
The error occurs because you are trying to edit a message without changing anything in it. If you need to use
editMessageText
oreditMessageReplyMarkup
but for some reason you don’t change anything then wrap the code in atry catch
block (you should always do that). And to remove the clock from the inline keyboard when you click, put some action in thecatch
block, for exampleanswerCallbackQuery
.In the above example the user didn’t pass the
reply_markup
parameter correctly, so the message didn’t change in any way and the error400 Bad Request: message is not modified
appeared.400 MESSAGE_NOT_MODIFIED