I recently created a Telegram bot that functions well for one-on-one conversations in groups. Now, I need it to post messages directly to my channel. Here’s the current script I’m using (after activating the bot with the /start command):
import telebot
api_token = '...'
bot_instance = telebot.TeleBot(api_token)
@bot_instance.message_handler(commands=['start'])
def greet_user(message):
response = 'Hello!'
bot_instance.send_message('@mychannelname', response)
bot_instance.polling(none_stop=True, interval=0)
Alternatively, I tried sending an HTML query:
https://api.telegram.org/bot/sendMessage?chat_id=@mychannelname&text=Hello
However, I receive an error message:
{"ok":false,"error_code":400,"description":"Bad Request: chat not found"}
.
I’ve already taken several steps following online guides:
- Ensured the bot has administrator access.
- Used @mychannelname instead of message.chat.id for send_message.
- Posted in the channel first, as the bot can only respond after being triggered.