我想使用 Telethon 庫中的方法獲取用戶的id和,這樣我就可以使用該方法發送訊息,而不必對我擁有的每個聯系人進行硬編碼。這是代碼first_nameGetContactsRequestidid
from telethon.sync import TelegramClient
from telethon import functions, types
with TelegramClient('session', api_id, api_hash) as client:
result = client(functions.contacts.GetContactsRequest(
hash=0
))
print(result.stringify())
這是 result.stringify() 的輸出
Contacts(
contacts=[
Contact()
Contact()
]
users=[
User(
id = xxx
first_name = 'name'
),
User(
id = xxx
first_name = 'name'
)
]
)
問題是我不確定如何決議這個,任何幫助將不勝感激
uj5u.com熱心網友回復:
您可以參考Contacts 此處的檔案。基本上,您需要做的就是遍歷用戶并id為每個用戶訪問。
for user in result.users:
print (user.id, user.first_name)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/438976.html
