电报机器人:editmessagereplymarkup方法不工作

发布于 2025-02-04 18:59:41 字数 1981 浏览 3 评论 0 原文

我已经使用node.js和node-telegram-bot-api模块开发了一个电报机器人,该模块向用户发送消息和直列键盘,我正在尝试的是在用户单击按钮后实现此目的键盘必须消失。我正在使用 editmessagereplymarkup ,但它给出了上述错误

参考:

代码的一部分:

bot.on('callback_query', function onCallbackQuery(example) {
    const action = example.data 
    const msg_id = example.message.from.id
    const chat_id = example.from.id

    //console.log(example.from.id)

    if (action == 'FM') {
        
        bot.editMessageReplyMarkup({
            reply_markup: {


                inline_keyboard: [
                    [
                       
                    ],

                ]
            }
        }, {
            chat_id: chat_id,
            message_id: msg_id
        });
    }
  });

错误:

Unhandled rejection Error: ETELEGRAM: 400 Bad Request: message to edit not found

我也尝试了以下解决方案,但它没有工作

参考: 单击后如何隐藏或删除inline按钮?

bot.on('callback_query', function onCallbackQuery(example) {
    const action = example.data 
    const msg_id = example.message.from.id
    const chat_id = example.from.id

    console.log(example.from.id)

    if (action == 'FM') {
        console.log(action)
        console.log("FM")
        console.log(msg_id)
        // console.log(example.message.message_id)

        bot.editMessageReplyMarkup({
            chat_id: chat_id,
            message_id: msg_id,
            reply_markup: JSON.stringify({
                keyboard: []
            })
        }

        );
    }


});

错误:

Unhandled rejection Error: ETELEGRAM: 400 Bad Request: message identifier is not specified

I've developed a telegram bot using Node.js and node-telegram-bot-api module that sends a message and an inline keyboard to the users, what I'm trying is to achieve that after the user clicks the button, the inline keyboard must disappear. I'm using editMessageReplyMarkup but it gives the mentioned errors

Reference: Method editMessageReplyMarkup removes inline keybord

Part of code:

bot.on('callback_query', function onCallbackQuery(example) {
    const action = example.data 
    const msg_id = example.message.from.id
    const chat_id = example.from.id

    //console.log(example.from.id)

    if (action == 'FM') {
        
        bot.editMessageReplyMarkup({
            reply_markup: {


                inline_keyboard: [
                    [
                       
                    ],

                ]
            }
        }, {
            chat_id: chat_id,
            message_id: msg_id
        });
    }
  });

Error:

Unhandled rejection Error: ETELEGRAM: 400 Bad Request: message to edit not found

I've tried the following solution as well but it doesn't work

Reference:
How hide or delete inline button after click?

bot.on('callback_query', function onCallbackQuery(example) {
    const action = example.data 
    const msg_id = example.message.from.id
    const chat_id = example.from.id

    console.log(example.from.id)

    if (action == 'FM') {
        console.log(action)
        console.log("FM")
        console.log(msg_id)
        // console.log(example.message.message_id)

        bot.editMessageReplyMarkup({
            chat_id: chat_id,
            message_id: msg_id,
            reply_markup: JSON.stringify({
                keyboard: []
            })
        }

        );
    }


});

Error:

Unhandled rejection Error: ETELEGRAM: 400 Bad Request: message identifier is not specified

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

总攻大人 2025-02-11 18:59:41

您指的是错误的msg_id。
应该

const msg_id = example.message.message_id
bot.editMessageReplyMarkup({
            reply_markup: {


                inline_keyboard: [
                    [

                    ],

                ]
            }
        }, {
            chat_id: chat_id,
            message_id: msg_id
        });

执行 console.log(示例)以清楚地了解响应

You're referring to wrong msg_id.
It should be

const msg_id = example.message.message_id
bot.editMessageReplyMarkup({
            reply_markup: {


                inline_keyboard: [
                    [

                    ],

                ]
            }
        }, {
            chat_id: chat_id,
            message_id: msg_id
        });

execute console.log(example) to get a clear idea of the response

灯下孤影 2025-02-11 18:59:41

使用此订单参数
bot.telegram.editmessagereplymarkup(chatid,messageId,newmarkup);

Use this order parameters
bot.telegram.editMessageReplyMarkup(chatId, messageId, newMarkup);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文