Can a Telegram bot retrieve a user's ID from their username?

Hey everyone, I’m working on a Telegram bot and I’m wondering if there’s a way to get a user’s ID just by knowing their username. I want to add a cool feature where my bot can tell you someone else’s user ID when you give it their username.

Does anyone know if the Telegram API has something like this? I’ve been looking through the docs but I’m not sure if I missed it or if it’s even possible.

It would be super helpful for my bot to do this. Has anyone tried something similar or know if it can be done? Thanks for any help or tips you can give me!

As someone who’s worked on a few Telegram bots, I can tell you that getting a user’s ID just from their username isn’t straightforward. The Telegram API doesn’t offer this functionality directly, which can be frustrating.

However, there’s a workaround I’ve used that might help. You could create a command like ‘/lookup @username’ in your bot. When a user sends this command, your bot can check if it has interacted with that username before and stored their ID. If not, it can inform the user that it needs that person to interact with the bot first.

This method isn’t perfect, but it’s helped me in similar situations. It allows your bot to gradually build up a database of usernames and IDs as people interact with it. Just remember to handle cases where usernames might change, and consider the privacy implications of storing this data.

Unfortunately, there’s no direct way to get a user’s ID just from their username through the Telegram API. It’s a limitation many developers face. The API requires some form of interaction with the user first. One workaround could be to create a command like ‘/getid @username’ where users can request IDs. Your bot could then store this info for future use. Keep in mind, this method would only work for users who’ve interacted with your bot before. It’s not ideal, but it’s a common approach many bot developers use to handle this limitation. You might want to consider if this approach fits your bot’s functionality or if there’s another way to achieve what you need without relying on user IDs.

nah, u cant get a user ID just from their username. telegram API doesnt have that. u need the user to interact with ur bot first, then u can grab their ID from the message data. its kinda annoying but thats how it works. maybe u could make ur bot ask users to send a message to get started?