Telegram 可以通过 id 聊天,不能通过 @name : Chat not found

标签 telegram telegram-bot python-telegram-bot

所以我使用@BotFather 制作了一个机器人,并通过我的帐户向它发送了消息。然后我使用@userinfobot 找到了我的帐户 ID 并发送了这个请求:

https://api.telegram.org/botTOKEN/sendMessage?chat_id=id&text=test 它工作正常 ok:true

但是,如果我尝试使用我的@username 而不是 id:

https://api.telegram.org/botTOKENg/sendMessage?chat_id=@username&text=test

我得到一个错误:

{
    "ok": false,
    "error_code": 400,
    "description": "Bad Request: chat not found"
}

查看我过去的代码,@ 方法曾经为我工作。有变化吗?

最佳答案

你必须使用id,你不能使用用户名。

将用户名作为参数仅适用于公共(public) channel 。

看看 Telegram Bot API documentation :

Description
Unique identifier for the target chat or username of the target channel (in the format @channelusername)

关于Telegram 可以通过 id 聊天,不能通过 @name : Chat not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57601429/

相关文章:

nginx - 无法在 Telegram bot webhook 中使用 Let's Encrypt 证书(自签名证书工作正常)

api - 错误 Telegram ID 和哈希 "Incorrect app name&#33"

python - 使用回调查询使用内联键盘更新消息

telegram - 一个账号可以有多少个Telegram公共(public) channel ?

python - Telegram:从不同的脚本向机器人发送消息

python - 如何运行我的 python 代码的多个实例?

python - 无法通过 http.client 正确重新连接

api - 我可以使用 Telegram bot api 检测我的机器人组吗

python - 如何将 Telegram 聊天机器人中的内联键盘设置为 python-telegram-bot 中的其他功能?

python - 如何在 telebot(pytelegramBotAPI)中获取 chat_id 和 message_id 以更新 Telegram bot(Python)中最后发送的消息