@Kogemyakavya4esl

Я создаю чат бота. При запуске код выдаёт ошибку: qlite3.OperationalError: no such table: queue Что я не так сделал?

Я уже создал таблицы в SQLiteStudio, но мне выдаёт что такой таблицы не существует. Что я сделал не так? Просто я только начинаю работать с бд.
Ниже мой код:

bot.py:
import config
import telebot
from telebot import types
from database import Database

db = Database('db.db')
bot = telebot.TeleBot(config.TOKEN)


@bot.message_handler(commands=['start'])
def start(message):
    markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
    item1 = types.KeyboardButton('️‍♂️Поиск собеседника...')
    markup.add(item1)

    bot.send_message(message.chat.id, 'Привет, {0.first_name}! Добро пожаловать в аннонимный чат! Нажми на поиск собеседника.'.format(message.from_user), reply_markup=markup)


@bot.message_handler(commands=['menu'])
def menu(message):
    markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
    item1 = types.KeyboardButton('️‍♂️Поиск собеседника...')
    markup.add(item1)

    bot.send_message(message.chat.id, ' Меню'.format(message.from_user), reply_markup=markup)


@bot.message_handler(content_types=['text'])
def bot_message(message):
    if message.chat.type == 'private':
        if message.text == '️‍♂️Поиск собеседника...':
            markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
            item1 = types.KeyboardButton('Остановить поиск')
            markup.add(item1)

            db.add_queue(message.chat.id)

            bot.send_message(message.chat.id, '️‍♂️Поиск собеседника...', reply_markup=markup)

        elif message.text == 'Остановить поиск':
            db.delete_queue(message.chat.id)
            bot.send_message(message.chat.id, 'Поиск остановлен напишите /menu')


bot.polling(none_stop=True)

database.py:
import sqlite3


class Database:
    def __init__(self, database_file):
        self.connection = sqlite3.connect(database_file, check_same_thread=False)
        self.cursor = self.connection.cursor()

    def add_queue(self, chat_id):
        with self.connection:
            return self.cursor.execute('INSERT INTO "queue" (chat_id) VALUES (?)', (chat_id,))

    def delete_queue(self, chat_id):
        with self.connection:
            return self.cursor.execute('DELETE FROM "queue" WHERE "chat_id" = ?', (chat_id,))

sql:
6506daf19570e323950877.png
  • Вопрос задан
  • 27 просмотров
Пригласить эксперта
Ответы на вопрос 1
SoreMix
@SoreMix
yellow
Значит не тот файл открываете
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы