Я хочу отправлять аудио через функцию, как я делаю с сообщениями и картинками, указав url песни к примеру.
Вот часть кода.
import vk_api
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
from vk_api.utils import get_random_id
from vk_api import VkUpload
import requests
def main():
vk_session = vk_api.VkApi(
token="типо мой токен")
vk = vk_session.get_api()
longpoll = VkBotLongPoll(vk_session, 'типо айди группы')
upload = VkUpload(vk_session)
attachments = []
session = requests.Session()
def send_audio(audio_url):
...
def send(mes):
vk.messages.send(chat_id=event.chat_id, random_id=get_random_id(), message=mes)
def send_img(image_url):
image = session.get(image_url, stream=True)
photo = upload.photo_messages(photos=image.raw)[0]
attachments.append('photo{}_{}'.format(photo['owner_id'], photo['id']))
vk.messages.send(chat_id=event.chat_id, attachment=','.join(attachments), random_id=get_random_id(),
message='')
attachments.remove('photo{}_{}'.format(photo['owner_id'], photo['id']))
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
if event.object.text.lower() == 'да':
send('Нет')
elif event.object.text.lower() == 'спасибо':
send_img("https://memepedia.ru/wp-content/uploads/2019/01/eqtw6mdl3ui.jpg")
elif event.object.text.lower() == 'аудио':
send_audio("https://cs9-20v4.vkuseraudio.net/p3/b01387b3526fdc.mp3?extra"
"=K9MTg1dmg61bIIyQy70wN9TY2HVd7ZlU3r-UqpAelZBJWyQH"
"-VgAp4XQiNhCbpNVYpRTkjO8PsNvmSADubxEEoS9AvEkbvNsvG70igHQSxmPgq15CbnDgmYueC7w1DhehEqjgTS7NdQbMQM")
if __name__ == '__main__':
main()