Answer the question
In order to leave comments, you need to log in
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
if event.type == VkEventType.MESSAGE_NEW and not event.from_me:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question