P
P
Proritsatel2021-03-26 15:14:17
Python
Proritsatel, 2021-03-26 15:14:17

How to accept multiple photos in a telegram bot?

The task before me was:
To accept on the side of the bot several photos that the user sends.
At first, I managed to accept only one photo.
Used pyTelegramBotApi
As a result, this is what happened:

@bot.message_handler(content_types=['photo'])
def handle_docs_photo(message):
    try:
        chat_id = message.chat.id
        file_info_1 = bot.get_file(message.photo[-1].file_id)
        bot.send_message(message.chat.id, file_info_1)
        downloaded_file = bot.download_file(file_info_1.file_path)
        
        src = dir + '\\' + file_info_1.file_path.split('/')[-1]
        bot.send_message(message.chat.id, src)
        with open(src, 'wb') as new_file:
            new_file.write(downloaded_file)

    except Exception as e:
        bot.reply_to(message, e)

But here a problem arose - if I send one photo without compression, then nothing happens,
if I send, for example, 4 photos, then the def handle_docs_photo (message) function: saves one photo less each time, in this case 3 photos.

What could be the problem and how can it be solved?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-03-26
@SoreMix

if I send one photo without compression, then nothing happens

Photo without compression - document. There is a special content-type for it - document

if I send for example 4 photos, then the function def handle_docs_photo(message): saves one photo less each time, in this case 3 photos

Is this all code? If yes, it works.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question