Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
The simplest option. It is worth adding checks in the form of try..except in case of errors.
@bot.message_handler(content_types=['document'])
def get_file(message):
file_name = message.document.file_name
file_info = bot.get_file(message.document.file_id)
with open(file_name, "wb") as f:
file_content = bot.download_file(file_info.file_path)
f.write(file_content)
bot.reply_to(message, f"OK. Сохранил {file_name}")
@bot.message_handler(content_types=['video'])
def get_file(message):
file_name = message.json['video']['file_name']
file_info = bot.get_file(message.video.file_id)
with open(file_name, "wb") as f:
file_content = bot.download_file(file_info.file_path)
f.write(file_content)
bot.reply_to(message, f"OK. Сохранил {file_name}")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question