如何保存从用户 Python 发送到远程机器人的文件?

How to save file which was sent to telebot from user Python?

我需要保存发送到电报机器人的文件。

import telebot
bot = "Here is my token"

@bot.message_handler(content_types='') #IDK what content type I need to use to receive every file
def addfile(message):
#Here I need to save file which was sent

看起来像这样:

@bot.message_handler(content_types=['document', 'photo', 'audio', 'video', 'voice']) # list relevant content types
def addfile(message):
    file_name = message.document.file_name
    file_info = bot.get_file(message.document.file_id)
    downloaded_file = bot.download_file(file_info.file_path)
    with open(file_name, 'wb') as new_file:
        new_file.write(downloaded_file)