S
S
Semyon2022-02-06 01:58:04
Python
Semyon, 2022-02-06 01:58:04

How to get a link to a Telegram user's profile photo?

How to get a link to a Telegram user's profile photo? Tried with getUserProfilePhotos method, but I get "400. Description: Bad Request: user not found" error. As an argument, I pass the IDs of users who have written to the bot at least once. Are there any restrictions on this method? Is it possible to get the profile photo of only certain users? I am using the pyTelegramBotAPI library.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lnerim, 2022-02-06
@galoned

@bot.message_handler(commands=["self_photo"])
def user_photo(message):
    photo = bot.get_user_profile_photos(message.from_user.id)
    bot.send_photo(message.chat.id, photo.photos[0][2].file_id)

Where 0 is the first or main photo in the profile, 2 is the size of the avatar (constant numbering 0..2, from smallest to largest). The code is not optimized for its absence.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question