import vk_api
from vk_api.bot_longpoll import VkBotEventType, VkBotLongPoll
from tok import token
vk_session = vk_api.VkApi(
token=token, api_version='5.131')
longpoll = VkBotLongPoll(vk_session, group_id=200082811)
def sender(id, text=None, attachments=None):
vk_session.method('messages.send',
{'user_id': id, 'message': text, 'random_id': 0, 'attachment': attachments})
for event in longpoll.listen():
print(event.type)
if event.type == VkBotEventType.MESSAGE_NEW:
print(event.object.message['attachments'][0])
if len(event.object.message['attachments']) != 0:
if event.object.message['attachments'][0]['type'] == 'audio_message':
doc = 'doc%s_%s_%s' % (event.object.message['attachments'][0]['audio_message']['owner_id'], event.object.message['attachments'][0]['audio_message']['id'], event.object.message['attachments'][0]['audio_message']['access_key'])
sender(id, text="audio", attachments=doc)