当我尝试编辑内联键盘 (node-telegram-bot-api) 时,为什么会收到 400 错误?
我正在使用简单的内联键盘发送消息。预期的结果是,当我单击按钮时,它会与消息文本一起更改。
但是按钮没有改变,我收到此错误:
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 包。
必须更改我的键盘的代码是:
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);
}
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
出现此错误的原因是您尝试编辑消息而不更改其中的任何内容。如果您需要使用
editMessageText
或editMessageReplyMarkup
但由于某种原因您没有更改任何内容,则将代码包装在try catch
块中(您应该始终这样做)。要在单击时从内联键盘中删除时钟,请在catch
块中添加一些操作,例如answerCallbackQuery
。在上面的示例中,用户没有正确传递
reply_markup
参数,因此消息没有以任何方式更改,并且错误400 Bad Request: message is not returned
出现了。400 MESSAGE_NOT_MODIFIED
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
我发现了错误。
方法
editMessageReplyMarkup()
需要参数replyMarkup
,内联键盘的 JSON 序列化对象。我的错误是我给出了整个reply_markup,而我被要求只提供inline_keyboard。代码现在看起来像这样:
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: