I’m trying to create a bot that forwards messages from a specific channel but I keep getting errors about missing parameters. The bot should forward a message when someone sends a command but it’s not working properly.
import telebot
from telebot import types
my_bot = telebot.TeleBot('bot_token_here')
@my_bot.message_handler(content_types=["text"])
def handle_request(msg):
my_bot.send_message(msg.chat.id, msg.text)
if __name__ == '__main__':
channel_id = "1234567890"
my_bot.forward_message('chat_id, 1234567890, 123')
my_bot.polling(none_stop=True)
I expected the bot to forward the message I want when a user enters a command but instead I get this error:
Traceback (most recent call last):
File "bot.py", line 12, in <module>
my_bot.forward_message('chat_id, 1234567890, 123')
TypeError: TeleBot.forward_message() missing 2 required positional arguments: 'from_chat_id' and 'message_id'
What am I doing wrong with the forward_message function? How should I pass the parameters correctly?
Your problem is with the forward_message function. You’re mashing all the parameters into one string instead of passing them separately. Use my_bot.forward_message(chat_id, from_chat_id, message_id) instead. Also, put this function call inside your message handler so it actually runs when someone sends a command. Just make sure your bot has permission to read from the source channel or it won’t work.
u’re passing the parameters as one str instead of separate args. It should be my_bot.forward_message(chat_id, from_chat_id, message_id) not 'chat_id, 1234567890, 123'. Also, why call forward_message outside tha handler? Put it inside when the user sends the command.
You’re calling the forward_message function wrong. You’re passing one string instead of three separate parameters. It should be my_bot.forward_message(chat_id, from_chat_id, message_id) with each parameter separate. Also, you’re calling this at the module level, so it runs immediately when the script starts - before any user does anything. Move the forward_message call inside your message handler and trigger it with specific commands. And make sure you’ve got the actual message ID you want to forward, not just a placeholder like ‘123’.