C
C
conn123r434342020-05-17 12:11:03
Python
conn123r43434, 2020-05-17 12:11:03

How to accept a photo from a user in a telegram bot?

there is such a code but it writes an error like there is no file_id

@bot.message_handler(content_types=['photo'])
    try:
        chat_id = message.chat.id

        file_info = bot.get_file(message.document.file_id)
        downloaded_file = bot.download_file(file_info.file_path)

        src = 'C:/Users/Timur/PycharmProjects/waltermark/documents/' + message.document.file_name;
        with open(src, 'wb') as new_file:
            new_file.write(downloaded_file)

        bot.reply_to(message, "Пожалуй, я сохраню это")
    except Exception as e:
        bot.reply_to(message, e)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
Zizya1, 2020-05-27
@Zizya1

@bot.message_handler(content_types=['photo'])
    try:
        file_info = bot.get_file(message.photo[len(message.photo) - 1].file_id)
        downloaded_file = bot.download_file(file_info.file_path)

        src = 'C:/Users/Timur/PycharmProjects/waltermark/documents/' + message.document.file_name;
        with open(src, 'wb') as new_file:
            new_file.write(downloaded_file)

        bot.reply_to(message, "Пожалуй, я сохраню это")
    except Exception as e:
        bot.reply_to(message, e)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question