Linked Questions

Popular Questions

I made a shop/bot. I use database to filter out data. But when two or more people use my bot - it start to lag and don't send messages. And console send multiple messages of ids.

import telebot
from telebot import types
import sqlite3

db = sqlite3.connect('database.db', check_same_thread = False)
sql = db.cursor()
sql.execute("""CREATE TABLE IF NOT EXISTS users(
    chatid TEXT,
    username TEXT,
    balance INT
    tovary TEXT

bot = telebot.TeleBot('Token')

mainmenu = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=2)
rules = types.KeyboardButton('Rules')
shop = types.KeyboardButton('Shop')
reviews = types.KeyboardButton('Reviews')
profile = types.KeyboardButton('Profile')
close = types.KeyboardButton('Close')
mainmenu.add(rules, shop, reviews, profile, close)

def start(message):
    def start(message):
        greeting = f'<b>Test greeting</b>'
        bot.send_message(, f'{greeting}', parse_mode='html', reply_markup=mainmenu)
    sql.execute(f"SELECT chatid FROM users WHERE chatid = '{}'")
    if sql.fetchone() is None:
        sql.execute(f"INSERT INTO users VALUES(?,?,?)", (, message.from_user.username, 0))
        for value in sql.execute("SELECT * FROM users"):

def handler(message):
    if message.text == "$money.test":
        sql.execute(f"UPDATE users SET balance = balance + 100 WHERE chatid = {}")
        for value in sql.execute(f"SELECT balance FROM users WHERE chatid = {}"):
            bot.send_message(, f"Хорошо, я выдал тебе 100 гривен на баланс.\n\nТвой баланс: {value[0]}", parse_mode='html')
    elif message.text == "$del.account":
        sql.execute(f"DELETE FROM users WHERE chatid = {}")
        bot.send_message(, "Аккаунт удалён.")


This is photo of console. enter image description here This is photo of telegram. enter image description here

What should I do to work with multiple users?

Related Questions