Answer the question
In order to leave comments, you need to log in
How to make the bot work for each user separately?
import vk_api, json, vk, sqlite3, statistics, json, datetime
from vk_api.longpoll import VkLongPoll, VkEventType
from vk_api.keyboard import VkKeyboard, VkKeyboardColor
from random import choice
db = sqlite3.connect(':memory:')
sql = db.cursor()
sql.execute('''CREATE TABLE IF NOT EXISTS Users(
id TEXT,
nik TEXT,
age TEXT);
''')
db.commit()
vk_token = 'token'
while True:
try:
vk_session = vk_api.VkApi(token = vk_token)
give = vk_session.get_api()
longpoll = VkLongPoll(vk_session)
except:
pass
finally:
break
def event1():
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW:
if event.to_me:
message = event.text
id = event.user_id
sql.execute("SELECT * FROM users WHERE id = ?", (id,))
user = sql.fetchone()
id_id = id
if user == None:# если нету в бд
vk_session.method('messages.send', {'peer_id' : id, 'message' : '⚠️ Вы ещё не зарегистрированы\n\nНапишите свой никнейм:', 'random_id' : 0})
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW and event.to_me:
message = event.text
id = event.user_id
nik = message
vk_session.method('messages.send', {'peer_id' : id, 'message' : '➡️ Напишите свой возраст:', 'random_id' : 0})
break
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW and event.to_me:
message = event.text
id = event.user_id
age = message
user = (id, nik, age)
sql.execute("INSERT INTO Users VALUES(?, ?, ?);", user)
db.commit()
vk_session.method('messages.send', {'peer_id' : id, 'message' : '✅ Регистрация завершена.\nВаша анкета\n'+user[1]+', '+user[2], 'random_id' : 0})
break
elif user != None:# если есть в бд
vk_session.method('messages.send', {'peer_id' : id, 'message' : '✅ Вы зарегистрированы', 'random_id' : 0})
event1()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question