T
T
Timyr2894372020-12-15 22:32:29
Python
Timyr289437, 2020-12-15 22:32:29

How to remember separately the text and image that you sent to the telegram bot?

I have a bot and I need it to save the text and photo to the database in one variable (I have this), I have absolutely no idea how to do this, here is the code that remembers the picture and it was sent in the document format, but for some reason into the variable " a" the text that I send along with the picture is not saved

@bot.message_handler(content_types=["document"])
def handle_docs_audio(message):
    try:
        a = message.text
        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:/new_project/images' + message.document.file_name
        with open(src, 'wb') as new_file:
            new_file.write(downloaded_file)

        bot.reply_to(message, "Пожалуй, я сохраню это")
        print(a)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-12-15
@Timyr289437

Because when submitting the document there is no text field , there is only a caption
So a = message.caption
Do print(message)it and see what comes up

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question