A
A
Alex Blinov2018-11-15 20:41:22
Python
Alex Blinov, 2018-11-15 20:41:22

How to make the bot code for the VK group work [PYTHON]?

Here:

# -*- coding: utf-8 -*-
import vk_api
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
def main():

    vk_session = vk_api.VkApi(token='#########################################')
    longpoll = VkBotLongPoll(vk_session, '#####')
    try:
      vk_session.auth(token_only=True)
    except vk_api.AuthError as error_msg:
      print(error_msg)
      return
    for event in longpoll.listen():
        if event.type == VkBotEventType.MESSAGE_NEW and event.to_me:
            api.messages.send(peer_id=event.user_id, message='Привет!')  !!!!Вот здесь мне выходит ошибка, что api не найдено
if __name__ == '__main__':
  main()

Here is a screenshot of the console. If the code is very thin, then pliz throw off a simple variant on Python.5bedafa564458146705484.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stockholm Syndrome, 2018-11-15
@CEPII

enable LongPoll in group settings
5bedbf24ad2b0926064602.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question