M
M
Mordred7692020-09-15 21:41:02
Python
Mordred769, 2020-09-15 21:41:02

Python telegram bot: how to send audio?

I am currently writing a bot for a telegram in python, the essence of which is sending music in the form of audio files. But, I don't know how to make it send music and how to write code for this. I reviewed everything on the Telegram Bot API website and on others too, but I didn’t find anything. Please help, and if possible, explain everything in as much detail as possible. Thanks in advance!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
soremix, 2020-09-15
@SoreMix

What's wrong with the documentation?
https://core.telegram.org/bots/api#sendaudio

params = {'chat_id': user_id}
files = {'audio': open(audio_name, 'rb')}
requests.post('https://api.telegram.org/botxx:xx/sendAudio', data=params, files=files)

K
kirillinyakin, 2020-09-15
@kirillinyakin

PyTelegramBotApi has a send_audio method like called.

audio = open('audio.mp3', 'rb')
bot.send_audio(chat_id, audio)

K
Kostyan4ik, 2020-09-16
@Kostyan4ik

If you want to send as a file then -

audio = open('audio.mp3', 'rb')
bot.send_document(chat_id, audio)

If in the form of an audio track, then kirillinyakin has already written an answer

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question