Answer the question
In order to leave comments, you need to log in
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
@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 questionAsk a Question
731 491 924 answers to any question