Telethon/readthedocs/extra/examples/users.rst

74 lines
1.6 KiB
ReStructuredText
Raw Normal View History

=====
Users
=====
.. note::
These examples assume you have read :ref:`accessing-the-full-api`.
Retrieving full information
***************************
If you need to retrieve the bio, biography or about information for an user
you should use :tl:`GetFullUser`:
.. code-block:: python
from telethon.tl.functions.users import GetFullUserRequest
2018-06-22 15:44:59 +03:00
async def main():
full = await client(GetFullUserRequest(user))
# or even
full = await client(GetFullUserRequest('username'))
2018-06-22 15:44:59 +03:00
bio = full.about
See :tl:`UserFull` to know what other fields you can access.
Updating your name and/or bio
*****************************
The first name, last name and bio (about) can all be changed with the same
request. Omitted fields won't change after invoking :tl:`UpdateProfile`:
.. code-block:: python
from telethon.tl.functions.account import UpdateProfileRequest
2018-06-22 15:44:59 +03:00
loop.run_until_complete(client(UpdateProfileRequest(a
bout='This is a test from Telethon'
)))
Updating your username
**********************
You need to use :tl:`account.UpdateUsername`:
.. code-block:: python
from telethon.tl.functions.account import UpdateUsernameRequest
2018-06-22 15:44:59 +03:00
loop.run_until_complete(client(UpdateUsernameRequest('new_username')))
Updating your profile photo
***************************
The easiest way is to upload a new file and use that as the profile photo
through :tl:`UploadProfilePhoto`:
.. code-block:: python
from telethon.tl.functions.photos import UploadProfilePhotoRequest
2018-06-22 15:44:59 +03:00
loop.run_until_complete(client(UploadProfilePhotoRequest(
client.upload_file('/path/to/some/file')
2018-06-22 15:44:59 +03:00
)))