0

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

asked Apr 2, 2024 at 19:38

1 Answer 1

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
answered Apr 3, 2024 at 9:00
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.