微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在Telethon中使用InputPhoto?

如何解决如何在Telethon中使用InputPhoto?

我想在电报中记录所有聊天参与者的昵称和照片。为此,我有这样的代码

client = TelegramClient(username,api_id,api_hash)

async def dump_all_participants(channel) -> list:
    offset_user = 0
    limit_user = 100

    all_participants = []
    filter_user = ChannelParticipantsSearch('')

    while True:
        participants = await client(GetParticipantsRequest(channel,filter_user,offset_user,limit_user,hash=0))
        if not participants.users:
            break
        all_participants.extend(participants.users)
        offset_user += len(participants.users)

    all_users_details = []

    for participant in all_participants:
        if participant.photo is None:
            photo = UNKNowN.STRING
        else:
            photo = participant.photo
        all_users_details.append({participant.id: [participant.username,photo]})
    return all_users_details

问题在于照片是Telethon对象。我无法取出照片,也不知道该怎么做

输出照片:UserProfilePhoto(photo_id=208135253786732667,photo_small=FileLocationTobedeprecated(volume_id=257125342,local_id=230348),photo_big=FileLocationTobedeprecated(volume_id=257125342,local_id=230350),dc_id=2,has_video=False)

我在文档documentation InputPhoto中找到了InputPhoto,希望对我有帮助,但是文档中没有使用示例,我无法弄清楚如何实现它。有人可以帮忙提供提示或示例,以获取照片吗?

解决方法

telethon中有解决此问题的方法:download_profile_photo

您可以将照片下载或存储在内存中以供以后使用。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。