import vk_api
from vk_api.longpoll import VkLongPoll, VkEventType
vk_session = vk_api.VkApi(token='токен')
longpoll = VkLongPoll(vk_session)
vk = vk_session.get_api()
def send_msg(peer_id: int, message: str, attachment: str = ""):
return vk.messages.send( **locals(), random_id=0)
while True:
try:
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW:
if event.text == "привет":
send_msg(event.peer_id, "Привет")
except Exception as e:
print(repr(e))
vk.setOptions({ token: 'token', pollingGroupId: id группы });