Answer the question
In order to leave comments, you need to log in
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='Ваш текст'
)
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'
Answer the question
In order to leave comments, you need to log in
You have a hodgepodge of different modules. First, it's import vk
not needed. Secondly, after declaring the variable longpoll
, do vk = vk_session.get_api()
and in the loop replace vk_api
withvk
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question