Answer the question
In order to leave comments, you need to log in
VK bot in Python gives an error, how to fix it?
Hello. The bot gives an error. How to fix it? I tried it myself. Honestly, I didn't understand. If possible, then in an understandable language, because I have very little knowledge of Python.
import random
import vk_api
from vk_api import VkApi
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType, VkBotMessageEvent, VkBotEvent
groupID =
token =
vk_session: VkApi = vk_api.VkApi(token=token)
longpoll = VkBotLongPoll(vk_session, groupID)
vk = vk_session.get_api()
def send(msg):
vk.messages.send(random_id=random.randint(0, 999999), message=msg, peer_id=peerID)
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW and event.object["text"].lower() == 'привет':
peerID = event.object['peer_id']
send('Привет')
Answer the question
In order to leave comments, you need to log in
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW and event.object ['message'] ["text"].lower() == 'hello':
peerID = event.object['peer_id ']
send('Hi')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question