我正在尝试运行一个代码,该代码将代表我每小时向我的组发送消息。但由于某种原因,它只向我最喜欢的人发送消息,而不向群组发送消息。安装了电话库。告诉我这段代码有什么问题? [![代码运行结果][1]][1]
import time
# Use your own values from my.telegram.org
api_id = 23932115
api_hash = '7dde9279e3c815a7539bb3f3d63942f294'
# The first parameter is the .session file name (absolute paths allowed)
with TelegramClient('anon', api_id, api_hash) as client:
client.loop.run_until_complete(client.send_message('me', 'Hello, myself!'))
async def main():
while True:
await client.send_message(1002172163245, '/Любой текст - тест 33/')
time.sleep(60)
with client:
client.loop.run_until_complete(main())
您是否在聊天或频道中发帖?开放了吗?
如果您发送到一个频道,那么一切都应该根据您的代码进行,但根据您编写的代码(根据 ID 判断),该频道应该是公开的。您可以在我的GitHub项目中更详细地了解其工作原理。
在你的代码中ID是1002172163245,我在TG中没有看到这样的ID。有-100XXXXXXXXX,这是“超级组”和频道的ID。
尝试在 id 前添加“ - ”