@helldess

Почему не удаётся вывести данные из базы?

В телеграм боте:
6326e185a3b8f766285172.png

Код базы данных:
from aiogram import Bot, Dispatcher, executor, types
import sqlite3


conn = sqlite3.connect('hellshopdb.db')
cursor = conn.cursor()


class BotDB:

    def __init__(self, db_file):
        self.conn = sqlite3.connect(db_file)
        self.cursor = self.conn.cursor()

    def user_exists(self, chat_id):
        result = self.cursor.execute("SELECT 'id' FROM 'users' WHERE 'chat_id' = ?", (chat_id,))
        return bool(len(result.fetchall()))

    def get_user_id(self, chat_id):
        self.cursor.execute("SELECT 'id' FROM 'users' WHERE 'chat_id' = ?", (chat_id,))
        return result.fetchone()[0]

    def add_user(self, chat_id):
        self.cursor.execute("INSERT OR IGNORE INTO 'users' ('chat_id') VALUES (?)", (chat_id,))
        return self.conn.commit()

    def get_balance(self, chat_id):
        self.cursor.execute("SELECT 'id' FROM 'users' WHERE 'chat_id' = ?", (chat_id,))
        return result.fetchone()[0]

    def close(self):
        self.conn.close()


Код хендлера:
@dp.message_handler(commands=['Профиль'])
@dp.message_handler(Text(equals='Профиль', ignore_case=True))
async def command_prof(message: types.Message):
    balance = BotDB.get_balance
    await message.bot.send_message(message.chat.id, f' Баланс: {balance}', reply_markup=op)
  • Вопрос задан
  • 195 просмотров
Пригласить эксперта
Ответы на вопрос 1
AlexNest
@AlexNest
Работаю с Python/Django
balance = BotDB.get_balance
Скобки где?
Ответ написан
Ваш ответ на вопрос

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

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