ResolveUsernameRequest

Both users and bots can use this request. See code examples.

---functions---
contacts.resolveUsername#f93ccba3 username:string = contacts.ResolvedPeer

Returns

contacts.ResolvedPeer

This type can only be an instance of:

ResolvedPeer

Parameters

usernamestring

Known RPC errors

This request can cause 4 known errors:

AuthKeyPermEmptyErrorThe method is unavailable for temporary authorization key, not bound to permanent.
SessionPasswordNeededErrorTwo-steps verification is enabled and a password is required.
UsernameInvalidErrorNobody is using this username, or the username is unacceptable. If the latter, it must match r"[a-zA-Z][\w\d]{3,30}[a-zA-Z\d]".
UsernameNotOccupiedErrorThe username is not in use by anyone else yet.

You can import these from telethon.errors.

Example

Please refer to the documentation of client.get_entity() to learn about the parameters and see several code examples on how to use it.

The method above is the recommended way to do it. If you need more control over the parameters or want to learn how it is implemented, open the details by clicking on the "Details" text.

from telethon.sync import TelegramClient
from telethon import functions, types

with TelegramClient(name, api_id, api_hash) as client:
    result = client(functions.contacts.ResolveUsernameRequest(
        username='some string here'
    ))
    print(result.stringify())