How can I make my bot send a message to a Telegram channel, and what is the significance of adding -100 in front of the channel ID?

huangapple go评论121阅读模式
英文:

How can I make my bot send a message to a Telegram channel, and what is the significance of adding -100 in front of the channel ID?

问题

如何让机器人发送消息到Telegram频道?

你必须在频道ID前面加上-100,这是ChatGPT告诉我的,我测试过,它有效。

“https://api.telegram.org/bot<token>/sendMessage?chat_id=-100<channelId>&text=<msg content>”

记得将机器人添加为管理员。

我在谷歌上搜索了很长时间,但没有人回答这个问题,感谢ChatGPT。

英文:

How to make a bot send a message to a telegram channel?

You must add -100 in front of the channel ID, this is what chatgpt told me, I tested it and it works.

“https://api.telegram.org/bot<token>/sendMessage?chat_id=-100<channelId>&text=<msg content>”

Remember to add the robot as an administrator.

I searched Google for a long time but no one answered this question, thanks to chatgpt.

答案1

得分: 0

chat_id 对于超级群组和频道,使用 Bot API 时总是以 -100 开头。为什么 Telegram 这样做是未知的。在 MTProto 中,chat_id 前面没有 -100,但由于你在使用 Bot API,所以这个数字是必要的,就像我说的那样。

对于公共频道,你也可以以字符串形式传递频道的 @username,如 文档 所述。

英文:

chat_id for supergroups and channels with Bot API always starts with -100. Why Telegram did that is unknown. With MTProto there's no -100 in front of the chat_id, however since you're using Bot API then this number is necessary, like I said.

For public channels you can also pass @username of the channel in form of a string as documentation describes.

huangapple
  • 本文由 发表于 2023年6月5日 09:57:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76403128.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定