Answer the question
In order to leave comments, you need to log in
How to download an audio message from a user in a telegram bot?
Expensive time of day. There is a question. I want to make a telegram bot that could read voice messages from the user and translate them into the desired language. The question is how to make the bot automatically understand that he was sent audio and save it to the specified directory?
PS I use the TelebotPyAPI library
Answer the question
In order to leave comments, you need to log in
import telebot
import requests
token = 'Токен'
bot = telebot.TeleBot(token)
@bot.message_handler(content_types=['voice','text'])
def repeat_all_message(message):
file_info = bot.get_file(message.voice.file_id)
file = requests.get('https://api.telegram.org/file/bot{0}/{1}'.format(token, file_info.file_path))
with open('voice.ogg','wb') as f:
f.write(file.content)
if __name__ == '__main__':
bot.polling(none_stop=True)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question