skip to Main Content

As the title says, is it possible to get userid using username?
I mean, I would like to add a feature to my bot that tells you the user id from an other user using his username.

Does Telegram API give an option to do this?

4

Answers


  1. No. It’s not possible right now.

    Login or Signup to reply.
  2. I believe what you mean by nickname is the username and userid is the unique id as described in the API documentation.It is still possible to do a reverse lookup using a bot.

    This is possible with a boosted version of the Official Telegram API, known as PWRTelegram API

    I quote from the documentation.

    Resolving of usernames not only with channels and groups but also with
    normal users and bots

    Update:

    Here is a library I made for this purpose:

    Update 2:

    I no longer maintain the above library, you can however still resolve usernames with a td-cli binary.

    Login or Signup to reply.
  3. You can use the pwrtelegram bot API to resolve usernames of bots and normal users.

    It will automagically resolve the usernames you provide in the chat_id parameter using a built in mtproto client.

    You can use usernames of bots and normal users in every method that requires the chat_id parameter, but to get info about a user/bot you can use the getChat method.

    Login or Signup to reply.
  4. The solution by Mohammod Sohail is partially wrong.

    There are ways to get a user_id from username, but online tools mentioned above use more than the bot API. They have a telegram client running on their server.
    That said there is a trick to get a user_id from username purely with bot API (doen’t always work).

    Lets say you are chatting with your friend X and you want to know his user_id. To get the user_id, forward one of your conversations to your bot. The bot will get the message author’s first name, username, user_id, timestamp, and so on in JSON format. Now you can extract the user_id from that. Note that this also works even if the user does not have a username, or if its a channel or another bot.

    Here is an bot implementation of the above:

    I’ve forwarded one of my friend’s message to the bot @get_id_bot
    Then the bot returns the username and id of my friend’s account

    GET ID BOT

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search