简体   繁体   中英

Telegram Bot API Python - telegram.error.BadRequest: Chat not found

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******

use it without " "

eg

import telegram

chat_id = 1382******
token = "TOKEN"

Channels ids usually starts with -100, so

chat_id = -1001382******

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM