如何使用 telethon 更改我的电报帐户名称?

How can I change my telegram account name using telethon?

我想使用 telethon 更改我的电报名称。我怎样才能做到这一点?我的 main.py 文件包含以下代码行,但它不起作用。你能指出我做错了什么吗?

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

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

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

Telethon 是异步库,您需要等待才能获得结果 进一步阅读 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())