【问题标题】:how to get chat_id and message_id in telebot(pytelegramBotAPI) to update last sent message in telegram bot(Python)如何在电报机器人(pytelegramBotAPI)中获取chat_id和message_id以更新电报机器人(Python)中最后发送的消息
【发布时间】:2018-07-31 10:45:13
【问题描述】:

这是我的一段代码

bot.edit_message_text(chat_id = CHAT_ID, message_id = MESSAGE_ID, text = "message has been updated", reply_markup=inline_keyboard)

【问题讨论】:

    标签: python telegram telegram-bot python-telegram-bot


    【解决方案1】:

    我认为你可以得到它:

    lastMessageId = message[-1].message_id
    lastChatId = message[-1].chat.id
    

    我不知道您为什么需要它,但我发送示例让您了解如何使用消息 ID 和用户 ID。

    你应该创建一个键盘:

    keyboard = types.InlineKeyboardMarkup()
    keyboard.add(types.InlineKeyboardButton('Yes', callback_data='yes'),
                 types.InlineKeyboardButton('No', callback_data='no'))
    

    创建命令:

    @bot.message_handler(commands=['like'])
    def like(message):
    
      cid = message.chat.id
      bot.send_message(cid, "Do you like it?", reply_markup=keyboard)
    

    创建回调:

    @bot.callback_query_handler(func=lambda call: call.data in ['yes', 'no'])
    def callback_handler(call):
    
        cid = call.message.chat.id
        mid = call.message.message_id
        answer = call.data
        update_lang(cid, answer)
        try:
            bot.edit_message_text("You voted: " + answer, cid, mid, reply_markup=keyboard)
        except:
            pass
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-19
      • 2016-03-11
      • 1970-01-01
      • 1970-01-01
      • 2017-09-01
      • 2018-02-25
      • 2021-04-21
      • 2019-10-30
      相关资源
      最近更新 更多