Answer the question
In order to leave comments, you need to log in
How to add a key phrase for which an answer will be given in a VK Api Python conversation?
With the code as on the screen, it gives an error as on the 2nd screen
import random
import requests
import vk_api
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
session = requests.Session()
vk_session = vk_api.VkApi(
token='token')
try:
vk_session._auth_token()
except vk_api.AuthError as error_msg:
print(error_msg)
exit(0)
longpoll = VkBotLongPoll(vk_session, group_id)
vk = vk_session.get_api()
response = event.text.lower()
while True:
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW and event.from_chat:
if event.from_chat:
vk.messages.send( #Отправляем собщение
chat_id=event.chat_id,
message='Ваш текст', random_id=random.randint(1, 10000000))
Answer the question
In order to leave comments, you need to log in
import vk_api
import random
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
vk = vk_api.VkApi(token="токен")
vk._auth_token()
vk.get_api()
longpoll = VkBotLongPoll(vk, айди группы)
while True:
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
if event.object.peer_id != event.object.from_id:
if event.object.text == "пинг"
vk.method("messages.send",
{
"chat_id": event.object.peer_id - 2000000000,
"message": "понг",
"random_id": random.randint(1, 2147483647)
}
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question