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