Как отправить через telebot аудио с локальных дисков
У меня такой вопрос можно ли отправить аудио с локального диска. Пытаюсь но не получается.
Я использую Python, telebot.
@bot.message_handler(commands=['start'])
def start_message(message):
bot.send_message(message.chat.id, 'Привет, ты написал мне /start')
@bot.message_handler(content_types=['text'])
def send_text(message):
if message.text == 'При':
bot.send_message(message.chat.id, 'Привет, мой создатель')
elif message.text == 'hello':
bot.send_audio(message.chat.id, 'C:\Program Files (x86)\bit\1.ogg')
elif message.text == 'Ясно!!!':
bot.send_sticker(message.chat.id, 'CAACAgIAAxkBAAMhXrEiC5rUiGT-ceiKkmiwjJou1xIAAg8DAAJtsEIDDrRMZLudXUYZBA')
Вот код но не получается отправить. Вот ошибка:
raise ApiException(msg, method_name, result) telebot.apihelper.ApiException: A request to the Telegram API was unsuccessful. The server returned HTTP 400 Bad Request. Response body: [b'{"ok":false,"error_code":400,"description":"Bad Request: wrong HTTP URL specified"}'] " 2020-05-08 20:19:25,300 (__init__.py:443 MainThread) ERROR - TeleBot: "A request to the Telegram API was unsuccessful. The server returned HTTP 400 Bad Request. Response body: [b'{"ok":false,"error_code":400,"description":"Bad Request: wrong HTTP URL specified"}']"
Ответы (2 шт):
Автор решения: D. Violet
→ Ссылка
откройте файл перед отправкой, а после закройте
audio = open(r'W:\Music\music\1_VIZE - Stars.mp3', 'rb')
bot.send_audio(message.chat.id, audio)
audio.close()
Автор решения: Дмитрий Еремеев
→ Ссылка
можно так, у меня работает:
with open(r'D:\python\output.mp3', 'rb') as audio:
bot.send_audio(message.from_user.id, audio)