Answer the question
In order to leave comments, you need to log in
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()
Answer the question
In order to leave comments, you need to log in
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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question