Telegram bot API: get message id to forward it

José María picture José María · Oct 31, 2015 · Viewed 19.8k times · Source

So, I need my bot to forward a message of a chat. But in order to do so, I need to get the id of the message I want to forward (it's an old message). How can I get the id of that message so I can send it?

This is the code I'm using

@bot.message_handler(func=lambda m: True)
def reply_ids(message):
    cid = message.chat.id
    bot.reply_to(message, "The message id is: " + str(message.message_id) + " This chat ID is: " + str(cid))

Answer

Dean Fenster picture Dean Fenster · Oct 31, 2015

When receiving a message, the id will be in message.message_id, as documented here.