如何使用机器人读取来自 Telegram 组的消息? [英] How to read messages from Telegram group with bot?
问题描述
我想连接一个简单的电报机器人来读取来自组的消息(我不是管理员).我已经将机器人添加到群组中,但它不起作用.
I would like to connect a simple telegram bot to read messages from a group, (where I'm not admin). I already added the bot to the group, but it doesn't work.
这是我在 Python 中的代码:
Here is the code I have in Python:
import telepot
from pprint import pprint
import time
from telepot.loop import MessageLoop
key = "MY API"
bot = telepot.Bot(key)
def handle(msg):
pprint(msg)
bot.message_loop(handle)
while 1:
time.sleep(10)
如果我打开(机器人的)聊天并写一条消息,一切正常.但是当有人在一个组中发送消息(我添加了机器人的地方)时,即使机器人在该组中,也不会发生任何事情.我做错了什么?我错过了什么吗?
If I open the chat (of the bot) and write a message, everything works well. But when someone send a message in a group (where I added the bot), even if the bot is in that group, nothing happen. What I'm doing wrong? Do I miss something?
非常感谢您的帮助!
推荐答案
您需要将 /setprivacy
更改为 Disable
,否则只能接收命令(以 <开头代码>/代码>).
You need to change /setprivacy
to Disable
, or you can only receive command (starts with /
).
您可以参考此处了解更多详情.
You can refer to here for more details.
这篇关于如何使用机器人读取来自 Telegram 组的消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!