S
S
Snowdevil2021-06-14 14:27:19
Python
Snowdevil, 2021-06-14 14:27:19

The VK bot answers even me in a dialogue, how to solve?

I wrote a bot for VKontakte PM, but, for example, if I write "Hello" in a dialogue with someone, then I will answer myself in the same dialogue. How to make, maybe, an exception, so that he would respond to all user_id except mine.

import sys
sys.path.insert(0, '../')
from vk_api.longpoll import VkLongPoll, VkEventType
import vk_api
from datetime import datetime
import data
import random
import time
login, password = '+79876543210', 'Pa$$word'
vk_session = vk_api.VkApi(token="54547567567831246b2fbd66b464a06f842b02eac3405000205856ac55e1e08db59fc63434bf2912eb")

session_api = vk_session.get_api()
longpoll = VkLongPoll(vk_session)

def send(vk_session, id_type, id, message=None, attachment=None, keyboard=None):
    vk_session.method('messages.send', {id_type: id, 'message': message, 'random_id': random.randint(-2147483648, +214783648)})

while True:
    for event in longpoll.listen():
        
        if event.type == VkEventType.MESSAGE_NEW:
            
            response = event.text.lower()

            if response == 'привет' or response == 'приветствую':
                    vk_session.method('messages.send', {'user_id': event.user_id, 'message': 'Привет!', 'random_id': 0})

            elif response == 'Пока':
                    vk_session.method('messages.send', {'user_id': event.user_id, 'message': 'До свидания!', 'random_id': 0})

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
WolfInChains, 2021-06-14
@Snowdevil

if event.type == VkEventType.MESSAGE_NEW and not event.from_me:

S
soremix, 2021-06-14
@SoreMix

It is logical that you need to check whether event.user_idyourid

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question