C
C
chainikk2018-11-03 17:32:43
Python
chainikk, 2018-11-03 17:32:43

How to solve attribute error?

There is a code, there is a cat in it. This is what .. 3 Post for the evening, but what can you do. So, here is the code itself

# coding: utf8
import vk_api
import requests
from vk_api.longpoll import VkLongPoll, VkEventType
import vk

session = requests.Session()
login, password = '', ''
vk_session = vk_api.VkApi(login, password)
try:
    vk_session.auth(token_only=True)
except vk_api.AuthError as error_msg:
    print(error_msg)
    
longpoll = VkLongPoll(vk_session)
for event in longpoll.listen():
    if event.type == VkEventType.MESSAGE_NEW and event.to_me and event.text:	
        if event.text == 'Первый вариант фразы' or event.text == 'Второй вариант фразы': #Если написали заданную фразу
            if event.from_chat: #Если написали в Беседе
                vk_api.messages.send(
                    chat_id=event.chat_id,
                    message='Ваш текст'
    )

And here is the error
File "C:\Users\Админ\AppData\Local\Programs\Python\Python37\dolboeb.py", line 20, in <module>
    vk_api.messages.send(
AttributeError: module 'vk_api' has no attribute 'messages'

When you change to vk, nothing changes. xz-3lpS4RDs.jpgThe message.send itself is in the VK api
https://vk.com/dev/messages.send

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-11-03
@chainikk

You have a hodgepodge of different modules. First, it's import vknot needed. Secondly, after declaring the variable longpoll, do vk = vk_session.get_api()and in the loop replace vk_apiwithvk

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question