Search code examples
python-3.xtelethon

How can I change my telegram account name using telethon?


I want to change my telegram name using telethon. How can I do this? My main.py file contains following lines of code but it didn't work. can you suggest what wrong I'm doing.

from telethon import TelegramClient
from telethon.tl.functions.account import UpdateProfileRequest

client = TelegramClient(<session>, <APICode>, <APIHash>)

with client:
    client(UpdateProfileRequest(first_name=f"Test"))

Solution

  • Telethon is asynchronous library you need to await in-order to get a result, further reading over here

    from telethon import TelegramClient
    from telethon.tl.functions.account import UpdateProfileRequest
    import asyncio
    
    client = TelegramClient(<session>, <APICode>, <APIHash>)
    
    
    async def main():
        async with client:
            await client(UpdateProfileRequest(first_name="Test"))
    
    asyncio.get_event_loop().run_until_complete(main())