M
M
Mason7202020-03-10 17:23:03
Python
Mason720, 2020-03-10 17:23:03

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('Привет')


5e67a1bf5c04b162726391.jpeg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
Wwwoper, 2020-03-10
@Mason720

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')

A
Andrey, 2020-03-10
@anerev

for event in longpoll.listen():
    if event.type == VkBotEventType.MESSAGE_NEW and event.object.text.lower() == 'привет':
        peerID = event.object.peer_id
        send('Привет')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question