admin管理员组文章数量:1400201
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);
}
})
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);
}
})
Share
Improve this question
asked Feb 23, 2022 at 9:14
elpideuselpideus
1252 silver badges12 bronze badges
1
- 1 which line of code throws that error? the error suggests you're sending something that "isn't modified" but the other end expects some change ... – Bravo Commented Feb 23, 2022 at 9:22
2 Answers
Reset to default 5The error occurs because you are trying to edit a message without changing anything in it. If you need to use editMessageText
or editMessageReplyMarkup
but for some reason you don't change anything then wrap the code in a try catch
block (you should always do that). And to remove the clock from the inline keyboard when you click, put some action in the catch
block, for example answerCallbackQuery
.
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 error 400 Bad Request: message is not modified
appeared.
400 MESSAGE_NOT_MODIFIED
I found out the error.
The method editMessageReplyMarkup()
requires the parameter
replyMarkup
, 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:
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);
}
})
本文标签:
版权声明:本文标题:javascript - Why do I get a 400 error when i'm trying to edit an inline keyboard (node-telegram-bot-api)? - Stack Overfl 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744201114a2594965.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论