S
S
swpavlov2020-01-19 15:30:28
Python
swpavlov, 2020-01-19 15:30:28

How to download a photo sent by telegram bot?

How to download a photo sent to a bot? If possible, please provide an example code. Thanks in advance
@bot.message_handler(content_types=["photo"])
def handle_docs_document(message):
photo_id = message.audio.file_id
file_info = bot.get_file(photo_id)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
swpavlov, 2020-01-19
@swpavlov

@bot.message_handler(content_types=['photo'])
def handle_docs_document(message):
    file_info = bot.get_file(message.photo[len(message.photo) - 1].file_id)
    downloaded_file = bot.download_file(file_info.file_path)
    src = '/home/pi/Desktop/bot2.0/photo' + message.photo[1].file_id
    with open(src, 'wb') as new_file:
        new_file.write(downloaded_file)
    bot.reply_to(message, "Фото добавлено")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question