Telethon 消息回复和个人资料照片下载不起作用

Telethon message reply and profile photo download not working

我从电视节目网站上复制了这些代码。 但是为什么我在对方的私密页面使用命令“.save”,头像没有落地呢?

from telethon import TelegramClient, events
client = TelegramClient('xxx', api_id, api_hash)

@client.on(events.NewMessage(outgoing=True, pattern=r'\.save'))
async def handler(event):
    if event.is_reply:
        replied = await event.get_reply_message()
        sender = replied.sender
        await client.download_profile_photo(sender)
        await event.respond('Saved your photo {}'.format(sender.username))
client.start()
client.run_until_disconnected()

您需要将 sender.id 作为参数放入 await client.download_profile_photo

我用了类似的功能,效果很好

@client.on(events.NewMessage(outgoing=True, pattern=("\+pet")))
async def pet(event): 
    reply = await event.get_reply_message() 
    await event.delete() 
    pic = await client.download_profile_photo(reply.sender_id) 
    petpet.make(pic, "res.gif") 
    await reply.reply(file="res.gif")