Remove telegram profile photo by telethon library or any API

有些话、适合烂在心里 提交于 2020-01-25 06:53:48

问题


I can't delete profile photo by telethon library or any else API

What I already did below (using telethon) but it doesn't work

from telethon import TelegramClient, sync
from telethon.tl.functions.photos import DeletePhotosRequest

api_id = "id"
api_hash = "hash"


client = TelegramClient("bot_5", api_id, api_hash)
client.start()

client(DeletePhotosRequest(client.get_profile_photos('me')))

I expected what this code would delete my profile photo

How can I delete it with API?


回答1:


this will work for you

from telethon.sync import TelegramClient
from telethon.tl.functions.photos import DeletePhotosRequest
from telethon.tl.types import InputPhoto


with TelegramClient('your session', api_id, api_hash) as client:
    p = client.get_profile_photos('me')[0]
    client(DeletePhotosRequest(
        id=[InputPhoto(
            id=p.id,
            access_hash=p.access_hash,
            file_reference=p.file_reference
        )]
    ))
  • get_profile_photos will return you a list


来源:https://stackoverflow.com/questions/58394174/remove-telegram-profile-photo-by-telethon-library-or-any-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!