本文介绍了不能“send_message"在 Telegram Bot API 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

在我自己的库中,我尝试使用来自 Telegram Bot API 的 "sendMessage" API 方法发送消息.我创建了一个名为my_channel123"的频道,我的用户名为my_username123".所以我是频道的管理员,也是唯一的用户.

In my own library I'm trying to send a message using "sendMessage" API method from Telegram Bot API. I've create a channel titled, say, "my_channel123" and my user name is "my_username123". So I'm an admin of the channel and the only user.

当我尝试从机器人向整个频道或我自己发送消息时,我收到错误 Bad request 400.这是我尝试这样做的方法:

When I'm trying to send a message to the whole channel or myself from a bot, I get an error Bad request 400. Here's how I'm trying to do that:

my_bot.send_message(chat_id="@my_channel123", text="tetfdsfd")

# or
my_bot.send_message(chat_id="@my_channel123my_username123", text= "tetfdsfd")

# or
my_bot.send_message(chat_id="@my_username123", text="tetfdsfd")

我相信错误出在频道 ID 或用户名或两者的格式中.所有这 3 个调用都正确吗,这意味着我用于 chat_id 的格式是否正确?

I believe the error is somewhere in the format of the ids of the channel or user name or both. Are all these 3 calls correct, meaning is the format I use for chat_id correct?

请注意,最有可能的情况是聊天的 ID 或用户名(或者更确切地说,格式)或其他内容因为我库中的其他 post 和 get 方法可以正常工作.

Note that most likely the probable case is the id of the chat or user_name (or rather, the format) or something else because other post and get methods in my library work properly.

推荐答案

您必须先将机器人添加为频道的管理员,然后它才能向频道发送消息.执行此操作后,您的第一行应该可以工作:

You have to add the bot to be an administrator of the channel before it can send messages to the channel. After you do that, your first line should work:

my_bot.send_message(chat_id="@my_channel123", text="tetfdsfd")

还要记住,@ 后面的内容应该是频道用户名,而不是标题.

Also remember that whatever follows the @ should be the channel username, not the title.

这篇关于不能“send_message"在 Telegram Bot API 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 23:14