S
S
samperirrrrr2020-06-07 11:37:24
Python
samperirrrrr, 2020-06-07 11:37:24

How to create a bot for a VK page in python?

Hello everyone, how to create a bot for a VK page in python. Looked everywhere for nothing. Help

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
WolfInChains, 2020-06-07
@samperirrrrr

import vk_api
from vk_api.longpoll import VkLongPoll, VkEventType

vk_session = vk_api.VkApi(token='токен')
longpoll = VkLongPoll(vk_session)
vk = vk_session.get_api()

def send_msg(peer_id: int, message: str, attachment: str = ""):
    return vk.messages.send( **locals(), random_id=0)

while True:
    try:
        for event in longpoll.listen():
            if event.type == VkEventType.MESSAGE_NEW:
                if event.text == "привет":
                   send_msg(event.peer_id, "Привет")
    except Exception as e:
        print(repr(e))

R
Reikoni, 2020-06-07
@ifullut

Well, what do you need a bot for? Write what you need it for and I will send you the finished code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question