@benzcrew

Что я делаю не так с register_message_handler в aiogram?

class Database:
    def __init__(self, db_file):
        self.connection = sqlite3.connect(db_file)
        self.cursor = self.connection.cursor()
        print("The database is connected successfully")

    def add_user(self, ID, username):
        with self.connection:
            try:
                self.cursor.execute("INSERT INTO 'user' VALUES (?, ?, ?, ?, ?, ?, ?)", (ID, "null", "null", "null", 'null', 'null', username))
            except: pass

    def add_client(self, ID):
        with self.connection:
            try:
                self.cursor.execute("INSERT INTO 'client' VALUES (?)", (ID,))
            except: pass

    def update_user_data(self, ID, a1, a2, a3, a4, a5):
        with self.connection:
            self.cursor.execute("UPDATE 'user' SET answer1 = ?, answer2 = ?, answer3 = ?, answer4 = ?, answer5 = ? WHERE user_id = ?", (a1, a2, a3,a4, a5, ID))

    def get_user_data(self, ID):
        with self.connection:
            return self.cursor.execute("SELECT * FROM 'user' WHERE user_id = ?", (ID,)).fetchmany()[0]

    def delete_zayavka(self, ID):
        with self.connection:
            return self.cursor.execute("DELETE FROM 'user' WHERE user_id = ?", (ID,))

    def client_exists(self, ID):
        with self.connection:
            result = self.cursor.execute("SELECT * FROM 'user' WHERE user_id = ?", (ID,)).fetchmany(1)
            if not bool(len(result)):
                return False
            else: return True

    def confirmed_user(self, ID):
        with self.connection:
            result = self.cursor.execute("SELECT * FROM 'client' WHERE user_id = ?", (ID,)).fetchmany(1)
            if not bool(len(result)):
                return False
            else: return True

# __________________________Обработка всех событий__________________________
def register_handlers_client(dp: Dispatcher):
    dp.register_callback_query_handler(send_state, cb.filter(action=["send", "application"]), state="*")
    dp.register_message_handler(command_start, commands=["start"])
    dp.register_callback_query_handler(access, text_contains="#")
    dp.register_callback_query_handler(start_state, cb.filter(action=["start_answer"]))
    dp.register_message_handler(answer1, state=get_answer.answer1)
    dp.register_message_handler(answer2, state=get_answer.answer2)
    dp.register_message_handler(answer3, state=get_answer.answer3)
    db.register_message_handler(answer4, state=get_answer.answer4)
    db.register_message_handler(answer5, state=get_answer.answer5)
# _________________________________________________________


register_handlers_client(dp)  # Запуск обработки событий


После этого кода вылазит ошибка:
AttributeError: 'Database' object has no attribute 'register_message_handler'
  • Вопрос задан
  • 145 просмотров
Решения вопроса 1
Vindicar
@Vindicar
RTFM!

dp.register_message_handler(answer3, state=get_answer.answer3)
db.register_message_handler(answer4, state=get_answer.answer4)

У тебя в паре месте перепутано dp и db.
Короткие названия они такие... коварные.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

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

Похожие вопросы