@danya2854

Почему возникает ошибка AttributeError: 'Database' object has no attribute 'cursor'?

При выполнении функции add_queue, почему‑то вылазит ошибка: AttributeError: 'Database' object has no attribute 'cursor' из‑за чего это, и как исправить?

import telebot
from telebot import types 
from database import Database

db = Database('db.db') 
bot = telebot.TeleBot("Токен")

@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, '<b>Воспроизводиться поиск..</b>',reply_markup = markup, parse_mode='html')


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.connection.cursor.execute("DELETE FROM `queue` WHERE `chat_id` = ?", (chat_id))
  • Вопрос задан
  • 10 просмотров
Пригласить эксперта
Ваш ответ на вопрос

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

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