Telegram API:使用Telethon获取组/频道中的成员数量



我已经尝试使用下面的代码,但它显示这个错误

AttributeError: 'coroutine' object没有属性'full_chat'

from telethon import client
from telethon.sync import TelegramClient
from telethon.tl.functions.channels import GetFullChannelRequest
client = TelegramClient('session_name', api_id, api_hash)
client.connect()
channel_connect = client.get_entity(channel_name)
channel_full_info = client(GetFullChannelRequest(channel=channel_connect))
print(channel_full_info.full_chat.participants_count)

这是因为full_chat不是协程的一个属性。

这里使用函数"get_participants"从GetFullChannelRequest

from telethon import TelegramClient, sync
from telethon.tl.functions.channels import GetFullChannelRequest

api_id = API ID
api_hash = 'API HASH'
client = TelegramClient('session_name', api_id, api_hash)
client.start()
if (client.is_user_authorized() == False):
phone_number = 'PHONE NUMBER'
client.send_code_request(phone_number)
myself = client.sign_in(phone_number, input('Enter code: '))
channel = client.get_entity('CHANNEL LINK')
members = client.get_participants(channel)
print(len(members))

最新更新