P
P
pt3n4ik_32021-07-16 22:00:20
Python
pt3n4ik_3, 2021-07-16 22:00:20

Sqlite3.OperationalError: no such table: users?

import telebot
import sqlite3
from telebot import types
import random

bot = telebot.TeleBot()

@bot.message_handler(commands=['reg'])
def start(message):
  connect = sqlite3.connect('ddlcusers.db')
  cursor = connect.cursor()

  cursor.execute('''CREATE TABLE IF NOT EXISTS login_id (
    id INTEGER,
    cash INT
  )''')

  connect.commit()

  #id
  usersid = message.from_user.id
  checkid = message.from_user.id

  cursor.execute(f'SELECT id FROM login_id WHERE id = {checkid}')
  if cursor.fetchone() is None:
    cursor.execute(f'INSERT INTO users VALUES (?, ?)', (usersid, 0))
    connect.commit()
    bot.send_message(message.from_user.id, "Вы успешно были добавлены в базу данных.")
  else:
    bot.send_message(message.from_user.id, 'Такой пользователь уже есть в базе данных бота.')
    bot.send_sticker(message.from_user.id, 'CAACAgIAAxkBAAECln1g8aeuFxR5g0bpgKlsQcrwHggrRAAC-BIAAkXUMEvqmAABi9b6IkogBA')


#delete user bd
@bot.message_handler(commands=['delete'])
def delete(message):
  bot.send_message(message.from_user.id, 'Ваш айди с базы данных был успешно удалён.')
  connect = sqlite3.connect('ddlcusers.db')
  cursor = connect.cursor()

  #delete id
  people_id = message.from_user.id
  cursor.execute(f'DELETE FROM login_id WHERE id = {people_id}')
  connect.commit()

@bot.message_handler(commands=['menu'])
def menu(message):
  markup = types.ReplyKeyboardMarkup(resize_keyboard = True)
  item1 = types.KeyboardButton('Рандомное число')
  item2 = types.KeyboardButton('Добавить деньги')

  markup.add(item1)

  bot.send_message(message.from_user.id, f'Привет!', reply_markup = markup)


@bot.message_handler(content_types=['text'])
def bot_message(message):
  if message.chat.type == 'private':
    if message.text == "Рандомное число":
      bot.send_message(message.chat.id, "Ваше чилсо: " + str(random.randint(0, 1000)))
    #elif message.text == "Добавить деньги":










bot.polling()


This is the same code, I get two errors, in bot polling, and cursor.execute(f'INSERT INTO users VALUES (?, ?)', (id, 0))
sqlite3.OperationalError: no such table: users, i I don’t know what to do anymore, I ask you to somehow enlighten me, because I am in despair. I searched how to fix the errors, but did not find anything.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vindicar, 2021-07-16
@pt3n4ik_3

Throw the text of the error into Google Translate, or something ...
He tells you in English and white that the users table has not been created. As mr_forlife explained, you need to create a table with a CREATE TABLE query. You only create login_id, not users.

N
nightbuzzz, 2022-04-20
@nightbuzzz

people harooooosh

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question