P
P
p1ugg2020-06-24 22:16:52
Python
p1ugg, 2020-06-24 22:16:52

How to make the bot work only for certain people?


I do it like this, but as a result, import vk_api
from vk_api.longpoll import VkLongPoll
from vk_api.longpoll import VkLongPoll, VkEventType
import requests, random, datetime, sys, time, argparse, os
from colorama import Fore, Back, does not work for more than one person Style

token = "token"

session = vk_api.VkApi(token=token)
longpoll = VkLongPoll(session)
vk = session.get_api()

for event in longpoll.listen():
if event.from_chat:
try:
_phone1 = event.text .lower()
textt = event.text
user = event.user_id
except:
continue
if event.user_id != user:
continue

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
soremix, 2020-06-24
@SoreMix

Please format your code before asking a question.
if event.user_id not in user:

Y
yamudaqq, 2020-06-25
@yamudaqq

create a list with user_ids of the people you need by type and then check after each message is receivedusers = [123213,53211,21213312,5454323]

if user in users:
     print('Нужный пользователь воспользовался ботом')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question