Ok, I know this is a newbie question but I’ve been stuck for a while now.
I just started using pythonTelegarmapi but I have no idea how to get message_id
of a message. How do i do it?
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.
"""
So, how to I retrieve the ID of a particular message in a chat/channel using Python Telegram Bot Api?
2
Answers
It’s in the
message
parameter that your function is receiving.message.message_id
should do the trick, see also https://github.com/eternnoir/pyTelegramBotAPI#types. Note that instead of'@from'
you should probably rather passmessage.chat.id
because IISC your code snippet doesn’t guarantee thatmessage
will be a message sent in the chat identified by the username'@from'
.You’ll need:
Where
mydebugid
is the ID you’re forwarding to.