F
F
Fedor2020-09-05 16:41:38
Python
Fedor, 2020-09-05 16:41:38

How can I make the message be processed first?

Hey! The essence of the error is simple, but I can not understand what the problem is.
5f5395b6f1465355963694.png

@bot.message_handler(content_types=['text'])
def send_text(message):
    if message.text == 'Зашифровать':  
        bot.send_message(message.chat.id, 'Пришлите файл для зашифровки')
        time.sleep(15)
        @bot.message_handler(content_types=['document'])
        def handle_file(message):
            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 = 'D:' + message.document.file_name;
                filename = message.document.file_name
                return filename
                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)

It is necessary that the file is processed, and not the message "Encryption"

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dima, 2020-09-05
@Arlidi

I'm not sure, but most likely it will help
you need to put this line separately from the block and everything involved in it in a separate block
@bot.message_handler(content_types=['document'])

I
IKIQ, 2020-09-05
@IKIQ

@bot.message_handler(regexp="Зашифровать")
def send_text(message):
    msg = bot.send_message(message.chat.id, 'Пришлите файл для зашифровки')
    bot.register_next_step_handler(msg, handle_file)

def handle_file(message):
    try:
        file_info = bot.get_file(message.document.file_id)
        downloaded_file = bot.download_file(file_info.file_path)
        src = 'D:' + message.document.file_name;
        filename = message.document.file_name
        return filename
        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