I want to create a bot to post my texts to a channel…
Can anyone help me with the code?
this is the code that I tried :
import telegram
token = "5002307835:AAGOu4f******************"
chat_id = "1382******"
bot = telegram.Bot(token)
def send_message(message):
return bot.send_message(chat_id,message)
send_message("HI")
but i got this error : telegram.error.BadRequest: Chat not found
also i tried : chat_id = "-1382******"
and chat_id = -1382******
and chat_id = 1382******
3
Answers
use it without
" "
e.g.
if not work, try it with
-
and no""
, it will works!e.g.
Channels ids usually starts with -100, so
Put it as integer
You can also get the channel id sending a message in the channel as normal user and handling it with the bot. In message.chat.id you will see the correct id
Or just forward a channel message to the bot https://t.me/nguLikJSONbot
First of all, you should be administrator of a channel and then send message to it.
For send text, file or photo with caption to a specific user, the target user should be member of your bot and then change chat_id to user id in telegram.