H
H
hellopythoners2021-01-21 02:40:45
Python
hellopythoners, 2021-01-21 02:40:45

How to make a VK bot reply only to a specific person?

Hello, how can I make the bot be distracted only by my message?

import vk_api
from vk_api.longpoll import VkLongPoll, VkEventType

vk_session = vk_api.VkApi(token='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:
                response = event.text.lower()
                if response == "пинг":
                   time.sleep(3)
                   send_msg(event.peer_id, "PONG")
      except Exception as e:
           print(repr(e))

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mors Clamor, 2021-01-21
@66demon666

Make a check if the sender id is yours - reply

P
Prizrak256, 2021-01-21
@Prizrak256

response = event.text.lower
if  response == "пинг" and peer_id == ваш_id:
      send_msg()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question