skip to Main Content

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))

5

Answers


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

    Login or Signup to reply.
  2. Recently I’ve been working with callback queries from inline buttons. One things I noticed is that in order to reply to the exact message that had the buttons Telegram needs to know both message.chat_id and message.message_id. You can try with both. This is more a comment then an answer but I don’t have enough reputation to comment.

    Login or Signup to reply.
  3. UPDATE: Now, It’s update.message.message_id

    Login or Signup to reply.
  4. If it is a supergroup or a channel, you can get the message_id by clicking on the message (in telegram web ) then choosing copy message link. the link will be in this form "https://t.me/channel_name/message_id"

    This solution is to find the message_id manually!!

    Login or Signup to reply.
  5. Using python, if you have a CommandHandler() you can read the chat_id and message_id like so:

    https://stackoverflow.com/a/72433953/1000741

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search