javascript - Why do I get a 400 error when i'm trying to edit an inline keyboard (node-telegram-bot-api)? - Stack Overfl

I am making a message with a simple inline keyboard. The expected result would be that when I click on

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
Add a ment  | 

2 Answers 2

Reset to default 5

The 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);
    }
})

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744201114a4562881.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信