gpt4 book ai didi

python - 在 telethon python Telegram 中向联系人发送消息

转载 作者:太空宇宙 更新时间:2023-11-03 14:05:05 26 4
gpt4 key购买 nike

如何查看我的所有联系人并向他们发送消息?我使用 Telethon(API Telegram python)。

from telethon.tl.functions.contacts import ResolveUsernameRequest
from telethon.tl.types import InputChannelEmpty
from telethon import TelegramClient
from telethon.tl.types.messages import Messages
from telethon.tl.types.contacts import Contacts
api_id = 1****
api_hash = '5fbd2d************************'
client = TelegramClient('arta0', api_id, api_hash)
client.connect()

最佳答案

只需将这一行添加到您的代码中:

contacts = client.invoke(GetContactsRequest(""))
print(contacts)

您应该会在结果中看到联系人。

要向联系人发送消息,您可以使用 telegram_client.py 中定义的 send_message 函数并在 InteractiveTelegramClient.py 中有一个示例.

for u in contacts.users: 
client.send_message(InputPeerUser(u.id, u.access_hash), "hi")

如果您需要更多详细信息,请在下方评论,我会尽力回复。

关于python - 在 telethon python Telegram 中向联系人发送消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44580847/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com