How to have telegram bot post messages to my channel and not its own channel [duplicate]
Asked Answered
P

1

9

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.

Picrite answered 26/2, 2022 at 9:59 Comment(1)
@sajjadrezaei He mentioned that the Bot is already an Admin of the channel ;)Cupriferous
C
13

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

Cupriferous answered 26/2, 2022 at 10:3 Comment(4)
I am using a channel called: GETID BOT in telegram. And if i forward message from any of my channel. its showing the same IDPicrite
What do you mean by showing the same ID? You send a message from multiple channels, but all have the same channel id?Cupriferous
What do you mean by "prepend -100" ? Example?Radmilla
Some ids of chats have to start with -100, so my channel with id 123456 will have to be -100123456 if it's a public channel. you may also try alternative telegram clients like exteraGram to get chat ids.Cupriferous

© 2022 - 2024 — McMap. All rights reserved.