[Python] How to find a user in Telegram by id?

Discussão em 'Python' iniciado por Stack, Abril 5, 2025.

  1. Stack

    Stack Membro Participativo

    I want to share my friend's telegram contact via bot. But my friend does not have a telegram username. I know his id number. How can I share it?

    I use PyTelegramBotApi. And my code is as follows:

    from telebot import TeleBot, types


    bot = TeleBot(token=TOKEN)

    @bot.message_handler(commands=['start'])
    def start_bot(message):
    text = "My friend contact"
    markup = types.InlineKeyboardMarkup()
    markup.add(types.InlineKeyboardButton(text='Contact', url="tg://user?id=<1427022865>"))
    bot.send_message(message.chat.id, text=text, reply_markup=markup)


    bot.polling()


    I read on the internet how to use url. But I make mistakes. Because: url="tg://user?id=<1427022865>"

    How to use it properly? Or is there another way?

    Continue reading...

Compartilhe esta Página