>>> %Run bot.py
Traceback (most recent call last):
File "D:\Анонимчатботтг\bot.py", line 5, in <module>
db = Database('db.db')
File "D:\Анонимчатботтг\database.py", line 7, in __init__
print('__init__:', self.cursor)
AttributeError: 'Database' object has no attribute 'cursor'
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,))
import telebot
from telebot import types
from database import Database
db = Database('db.db')
bot = telebot.TeleBot("Токен")
@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, f'<b>{message.from_user.first_name}</b>, добро пожаловать в нашего замечательного бота!\nНажмите на кнопку поиск собеседника или \nнапишите "/search" чтобы начать поиск',parse_mode='html', 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, '<b>Воспроизводиться поиск..</b>',reply_markup = markup, parse_mode='html')
elif message.text == '❌ Остановить поиск':
db.delete_queue(message.chat.id)
bot.send_message(message.chat.id, '❌ Поиск остановлен.', parse_mode='html')
@bot.message_handler(commands=['search'])
def search(message):
bot.send_message(message.chat.id, '<b>Воспроизводиться поиск..</b>',parse_mode='html')
bot.polling(none_stop=True)
Traceback (most recent call last):
File "D:\Анонимчатботтг\bot.py", line 35, in <module>
bot.polling(none_stop=True)
File "D:\Python\lib\site-packages\telebot\__init__.py", line 1198, in polling
self.__threaded_polling(non_stop=non_stop, interval=interval, timeout=timeout, long_polling_timeout=long_polling_timeout,
File "D:\Python\lib\site-packages\telebot\__init__.py", line 1273, in __threaded_polling
raise e
File "D:\Python\lib\site-packages\telebot\__init__.py", line 1235, in __threaded_polling
self.worker_pool.raise_exceptions()
File "D:\Python\lib\site-packages\telebot\util.py", line 150, in raise_exceptions
raise self.exception_info
File "D:\Python\lib\site-packages\telebot\util.py", line 93, in run
task(*args, **kwargs)
File "D:\Python\lib\site-packages\telebot\__init__.py", line 8945, in _run_middlewares_and_handler
result = handler['function'](message)
File "D:\Анонимчатботтг\bot.py", line 23, in bot_message
db.add_queue(message.chat.id)
File "D:\Анонимчатботтг\database.py", line 10, in add_queue
return self.cursor.execute("INSERT INTO `queue` (`chat_id`) VALUES (?)", (chat_id))
AttributeError: 'Database' object has no attribute 'cursor'
>>>
Traceback (most recent call last):
File "D:\Анонимчатботтг\bot.py", line 35, in <module>
bot.polling(none_stop=True)
File "D:\Python\lib\site-packages\telebot\__init__.py", line 1198, in polling
self.__threaded_polling(non_stop=non_stop, interval=interval, timeout=timeout, long_polling_timeout=long_polling_timeout,
File "D:\Python\lib\site-packages\telebot\__init__.py", line 1273, in __threaded_polling
raise e
File "D:\Python\lib\site-packages\telebot\__init__.py", line 1235, in __threaded_polling
self.worker_pool.raise_exceptions()
File "D:\Python\lib\site-packages\telebot\util.py", line 150, in raise_exceptions
raise self.exception_info
File "D:\Python\lib\site-packages\telebot\util.py", line 93, in run
task(*args, **kwargs)
File "D:\Python\lib\site-packages\telebot\__init__.py", line 8945, in _run_middlewares_and_handler
result = handler['function'](message)
File "D:\Анонимчатботтг\bot.py", line 23, in bot_message
db.add_queue(message.chat.id)
File "D:\Анонимчатботтг\database.py", line 10, in add_queue
return self.cursor.execute("INSERT INTO `queue` (`chat_id`) VALUES (?)", (chat_id))
AttributeError: 'Database' object has no attribute 'cursor'