I'm trying to save the attached sound from a telegram to my computer, but I don't understand how to do it. I found a similar code, but it doesn't work.
@bot.message_handler(content_types=['document', 'photo', 'audio','video', 'voice'])
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)
for some reason, when sending audio files, the bot does not see them at all and displays the value None
1 Answer 1
I found a solution:
@bot.message_handler(content_types=['audio'])
def process_audio(message):
downloaded_file = bot.download_file(bot.get_file(message.audio.file_id).file_path)
with open(message.audio.file_name, 'wb') as new_file:
new_file.write(downloaded_file)
L Tyrone
8,37123 gold badges34 silver badges47 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Explore related questions
See similar questions with these tags.
lang-py