Answer the question
In order to leave comments, you need to log in
How to save data in VK bot?
I wrote a couple of simple VK bots. In one of them, I store the user id in a regular variable. At the end, this variable is reset to zero. But if several people write to the bot at the same time. The data in these variables is confused. What to do in such a situation? I am using the vkbottle library.
Answer the question
In order to leave comments, you need to log in
Good evening, I generally understand more about tg bots, but I think the principle is the same. It will be easier to keep id, message and whatever in any database, for example the same sqlite3. And already from it to add / take the necessary data.
For example, such a database takes the user's id, nickname and message text:
import sqlite3
conn = sqlite3.connect('base.db', check_same_thread=False)
cursor = conn.cursor()
def create_table():
cursor.execute('CREATE TABLE data (user_id integer, user_name text,messageg text)')
conn.commit()
def db_table_val(user_id: int, user_name: str, messageg: str):
cursor.execute('INSERT INTO data (user_id, user_name, messageg) VALUES (?, ?, ?)',
(user_id, user_name, messageg))
conn.commit()
def take():
print("Results from a LIKE query:")
sql = "SELECT messageg FROM data"
cursor.execute(sql)
print(cursor.fetchall())
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question