Answer the question
In order to leave comments, you need to log in
How to send a voice message with a VK bot?
This is how I try to send a voice message on behalf of the bot
id = str(messages["items"][0]["last_message"]["from_id"])
upload = vk.method("docs.getMessagesUploadServer", {"type": "audio_message", "peer_id": id})
jsn = requests.post(upload["upload_url"], files={'file': open(path + f'_{i}.ogg', 'rb')}).json()
save = vk.method("docs.save", {"file": jsn["file"]})
send = 'doc{}_{}'.format(save["audio_message"]["owner_id"], save["audio_message"]["id"])
vk.method('messages.send',
{"peer_id": int(id),
"attachment": send, "random_id": random.randint(0, 2147483647)})
Answer the question
In order to leave comments, you need to log in
Try using the following:
audio = open('lol.mp3','rb')
a = session_api.docs.getMessagesUploadServer(type='audio_message')
b = requests.post(a['upload_url'], files={'file':audio}).json()
c = session_api.docs.save(file=b['file'])
doc = 'doc%s_%s_%s'%(c['audio_message']['owner_id'],c['audio_message']['id'],c['audio_message']['access_key'])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question