Вместо
VkLongPoll, VkEventType
использовать
VkBotLongPoll, VkBotEventType
Пример
import vk_api
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
vk = vk_api.VkApi(token="ТОКЕН")
vk._auth_token()
vk.get_api()
longpoll = VkBotLongPoll(vk, АЙДИ ГРУППЫ)
def send_msg(peer_id: int, message: str, attachment: str = ""):
return vk.method("messages.send", {**locals(), "random_id": 0})
while True:
try:
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
if event.object.peer_id != event.object.from_id: #Для беседы
if event.object.text == "Привет":
send_msg(event.obj.peer_id, "Пока")
else:
send_msg(event.obj.peer_id, "Я не знаю такой команды")
if event.object.peer_id == event.object.from_id: #Для Лс
if event.object.text == "Привет":
send_msg(event.obj.peer_id, "Пока")
else:
send_msg(event.obj.peer_id, "Я не знаю такой команды")
except Exception as e:
print(repr(e))