How to create a Telegram bot that forwards messages to another chat

I’m developing a Telegram bot and I’m looking for assistance with its forwarding feature. I currently have a simple echo bot that sends messages back to the users:

import settings
import telebot

my_bot = telebot.TeleBot(settings.api_key)

@my_bot.message_handler(content_types=["text"])
def echo_handler(msg): 
    my_bot.send_message(msg.chat.id, msg.text)

if __name__ == '__main__':
     my_bot.polling(none_stop=True)

What I need now is to modify this bot so that it forwards the received messages to another specified chat instead of just repeating them. I’ve tried using this code snippet:

target_chat = '298765432'
my_bot.forward_message(target_chat, msg.chat.id, msg.text)

Unfortunately, this doesn’t seem to work. Can someone guide me on how to correctly implement message forwarding to another chat in my Telegram bot? I’m having trouble figuring out the right way to use the forward_message function.

Your forward_message function has the wrong parameters. You’re passing msg.text as the third argument, but it needs msg.message_id instead. The function looks for the message ID to find and forward the specific message - it doesn’t use the text.

Here’s the fix:

target_chat = '298765432'
my_bot.forward_message(target_chat, msg.chat.id, msg.message_id)

I ran into this same thing when I started with Telegram bots. The docs aren’t always clear about it. Double-check that your target chat ID is right and your bot has permission to post there.

Had the exact same issue with my first forwarding bot. Yeah, you need msg.message_id instead of msg.text like others said, but there’s another thing that’ll trip you up. Your bot needs to be in the target chat with message permissions. For private chats, the user has to start the bot first. For groups, just add it as a member with the right permissions. Also, some messages (like service messages) can’t be forwarded at all, so wrap your forward_message call in error handling or it’ll crash on you.

hey alice, quick fix - use msg.message_id instead of msg.text for the third parameter. forward_message needs the message id to work. so it’s my_bot.forward_message(target_chat, msg.chat.id, msg.message_id) and you’re set!