如何通过电报获取消息的消息 ID python api

How to get message id of a message through telegram python api

好的,我知道这是一个新手问题,但我已经被困了一段时间了。

我刚开始使用 pythonTelegarmapi,但不知道如何获取 message_id 消息。我该怎么做?

import os
import telebot

API_KEY =  "API_KEY"

# Getting the bot instance
bot = telebot.TeleBot(API_KEY)

# Forward mesasage
# From https://core.telegram.org5/bots/api#forwardmessage
@bot.message_handler(commands=['forward'])
def forward(message):
    bot.forward_message('@send_to','@from', 1, False)
                                           ^^^
#                                          Here is supposed to be the message_id but I don't know how to get that. 

"""

那么,如何使用 Python Telegram Bot Api 在 chat/channel 中检索特定消息的 ID?

它在您的函数接收的 message 参数中。 message.message_id 应该可以解决问题,另请参阅 https://github.com/eternnoir/pyTelegramBotAPI#types。请注意,而不是 '@from' 你应该更愿意传递 message.chat.id 因为 IISC 你的代码片段不保证 message 将是在用户名 [=12= 识别的聊天中发送的消息].

您需要:

bot.forward_message(mydebugid, message.chat.id, message.message_id, False)

其中 mydebugid 是您要转发到的 ID。


import os
import telebot

API_KEY = "--"

# Getting the bot instance
bot = telebot.TeleBot(API_KEY)

mydebugid = 123456

bot.send_message(mydebugid, "Wake")

# Forward mesasage
@bot.message_handler(commands=['forward'])
def forward(message):
    bot.forward_message(mydebugid, message.chat.id, message.message_id, False)


bot.polling()