How to have telegram bot post messages to my channel and not its own channel

Viewed 2743

I have a telegram bot which publishes messages to somebot using this code.

import telegram
from telegram import ParseMode
def send_msg(text):
    token = '1*****:AAF*************esns'
    chat_id = "34*****4"
    bot = telegram.Bot(token=token)
    
    bot.sendMessage(chat_id=chat_id, text=text, parse_mode=ParseMode.MARKDOWN_V2)

What I was wondering is if it is possible for the telegram bot to send message to my channel where i have made it an admin and not its own channel called somebot.

1 Answers

As your Bot already is an Admin of the channel you want it to post in, you just need to change the chat_id for Bot.send_message() to the one of the channel the bot is meant to send posts in.

You can obtain this ID for example by using Bgram Telegram client or IDBot. Be aware that you may have to prepend -100 to the ID you get as channels are just special super-groups.

Hope it helps ;)

Related