D
D
Dizone2021-11-13 11:13:44
Python
Dizone, 2021-11-13 11:13:44

When writing code for a VK conversation, I got an error AttributeError: 'VkApi' object has no attribute 'listen', what should I do?

import vk_api
from vk_api.bot_longpoll import  VkBotLongPoll, VkBotEventType

vk_session = vk_api.VkApi(token =  "...")
longpoll = vk_api.VkApi(vk_session,  "...")

def sender(id, text):
    vk_session.method('messages.send', {'chad_id' : id, 'message' : text, 'random_id' : 0})

for event in longpoll.listen():
  if event.type == VkBotEventType.MESSAGE_NEW:
    if event.from_chat:

      id = event.chat_id
      msg = event.object.message['text'].lower()

      try:
        dey = event.message.action['type']
        invite_id = event.message.action['member_id']
      except:
        dey = ''
        invite_id = -100

      if dey == 'chat_invite_user':
        sender(id, f'✔Приветствуем вас в нашей беседе, @id {invite_id} пожалуйста прочитайте правила беседы и не нарушайте их.')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-11-13
@Dizone

Be more attentivelongpoll = VkBotLongPoll(vk_session, "...")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question