-2

I am trying to create my own admin bot that can handle a lot of the admin stuff.

how do I get a users ID via their username? I don't see any way to get it from the API, or did I just miss it?

If you are interested, I'm using Telebot.

user = bot.get_chat(username)
SA ED
  • 1
  • 1
    Does this answer your question? [Telegram Bot: Is it possible to get userid using username?](https://stackoverflow.com/questions/37644603/telegram-bot-is-it-possible-to-get-userid-using-username) – 0stone0 Aug 23 '23 at 11:25

1 Answers1

0

In Telegram, you cannot directly obtain a user's unique identifier (UserID) using their username unless the user has interacted with your bot at least once. Once a user interacts with your bot, you can obtain their UserID.

Here's how you can use the telebot library to get a user's UserID :

@bot.message_handler(commands=['start'])
def start(message):
    user_id = message.from_user.id
    bot.reply_to(message, f"Your UserID is {user_id}.")