D
D
dyrtage62020-06-13 22:56:21
Python
dyrtage6, 2020-06-13 22:56:21

I can’t solve the problem with vk_api, I get an error that there is no VkEventType (python3) library. What to do?

I'm trying to make a bot for friends. Added wikipedia module to find terms and more. But an error occurs -
Traceback (most recent call last):
File "/home/dyrtage2006/vbotk.py", line 31, in
if event.type == VkEventType.MESSAGE_NEW:
NameError: name 'VkEventType' is not

defined the code -

import vk_api
    from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
    import random
    import wikipedia
    
    vk = vk_api.VkApi(token="какой то токен")
    vk._auth_token()
    vk.get_api()
    longpoll = VkBotLongPoll(vk, какой то айди)
    
    play = ["Бумага", "Ножницы", "Камень"]
    wikipedia.set_lang("RU")
    
    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.lower() == "привет":
                        vk.method("messages.send", {"peer_id": event.object.peer_id, "message": "Привет! Я бот беседы. Я умею играть(команда 'Игра'), смотреть информацию с Википедии(в стадии разработки). Остально тоже в стадии разработки.",
                                                    "random_id": 0})
                    if event.object.text.lower() == "игра":
                        vk.method("messages.send", {"peer_id": event.object.peer_id, "message": "Давай сыграем в игру 'Камень, ножницы, бумага'. Напиши свой ход и я его сделаю",
                                                    "random_id": 0})
                    if event.object.text.lower() == "бумага" or event.object.text.lower() == "ножницы" or event.object.text.lower() == "камень":
                        vk.method("messages.send", {"peer_id": event.object.peer_id, "message": random.choice(play) + ". Теперь сам думай кто выиграл, потому что разработчику лень додумывать",
                                                    "random_id": 0})
                    if event.object.text.lower() == "вики":
                        vk.method("messages.send", {"peer_id": event.object.peer_id, "message": "Введите запрос",
                                                    "random_id": 0})
                    for event in longpoll.listen():
                        if event.type == VkEventType.MESSAGE_NEW:
                            if event.from_chat:
                                vk.method("messages.send", {"peer_id": event.object.peer_id, "message": "Вот что я нашёл: \n" + str(wikipedia.summary(event.text)),
                                                    "random_id": 0})


If I add VkEventType, then the error comes out again -
Traceback (most recent call last):
File "/home/dyrtage2006/vbotk.py", line 2, in
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType, VkEventType
ImportError: cannot import name 'VkEventType ' from 'vk_api.bot_longpoll Tell me

how to do it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-06-14
@SoreMix

This variable is in the vk_api library, import from it. You pull from longpolling

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question