所以我使用@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/