Search code examples
pythontelegram-botpython-telegram-bot

Is there a way to change avatar in telegram bot using python?


I was trying to find some documentation, but i`ve failed. I would be grateful if you send me doc or example how to do it.


Solution

  • In order to change your profile photo you should use MTPROTOAPI. One of the good libraries written in Python is called telethon. You can check here on how to update profile information.

    install telethon:

    python3 -m pip install --upgrade telethon
    

    update profile photo:

    import asyncio
    from telethon import TelegramClient
    from telethon.tl.functions.photos import UploadProfilePhotoRequest
    
    
    # Use your own values from my.telegram.org
    api_id = 12345
    api_hash = '0123456789abcdef0123456789abcdef'
    
    client = await TelegramClient('anon', api_id, api_hash)
    
    await client(UploadProfilePhotoRequest(
        await client.upload_file('/path/to/some/file')
    ))