import vk_api.vk_api
from vk_api.bot_longpoll import VkBotLongPoll
from vk_api.bot_longpoll import VkBotEventType
vk = vk_api.VkApi(token=токен")
long_poll = VkBotLongPoll(vk, айди группы)
vk_api = vk.get_api()
for event in long_poll.listen():
print(event)
if event.type == VkBotEventType.MESSAGE_NEW:
print("message")
elif event.type == VkBotEventType.MESSAGE_EVENT:
print('button')
Вывод:
<<class 'vk_api.bot_longpoll.VkBotEvent'>({'type': 'message_event', 'object': {'user_id': 325017603, 'peer_id': 2000000003, 'event_id': 'c9e90aab7b38', 'payload': {'button': 'bot'}, 'conv
ersation_message_id': 2741}, 'group_id': 161256065, 'event_id': '08285246239cca167e6d72d035920b5ea528c5ed'})>
Traceback (most recent call last):
File "C:\Bot\Elite\donut.py", line 18, in <module>
elif event.type == VkBotEventType.MESSAGE_EVENT:
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\enum.py", line 405, in __getattr__
raise AttributeError(name) from None
AttributeError: MESSAGE_EVENT
[{'member_id': -161256065, 'invited_by': -161256065, 'join_date': 1629293809, 'is_admin': True, 'is_owner': True}, {'member_id': 312885997, 'can_kick': True, 'invited_by': -161256065, 'join_date': 1629293819, 'is_admin': True}, {'member_id': 325017603, 'can_kick
': True, 'invited_by': 312885997, 'join_date': 1629293825, 'is_admin': True}, {'member_id': 598501674, 'can_kick': True, 'invited_by': 312885997, 'join_date': 1629308384}]