Пытаюсь написать регистрацию в Тг боте. При вводе команды start ничего не происходит, ошибок тоже не выдает
db = Database('database.db')
@bot.message_handler(commands=['start'])
def start(message: types.Message):
if not db.user_exists(message.from_user.id):
db.add_user(message.from_user.id)
bot.send_message(message.chat.id, "Как к тебе обращаться?")
else:
bot.send_message(message.chat.id, "Вы уже зарегистрированы.")
@bot.message_handler()
def bot_message(message: types.Message):
if db.get_signup(message.from_user.id) == "setnickname":
if len(message.text) > 20:
bot.send_message(message.chat.id, "Никнейм не может содержать больше 20 символов!")
elif '/' in message.text:
bot.send_message(message.chat.id, "Символ / нельзя использовать в никнейме")
else:
db.set_nickname(message.from_user.id, message.text)
db.set_signup(message.from_user.id, 'complete')
bot.send_message(message.chat.id, "Поздравляю, вы успешно зарегистрировались!")
else:
bot.send_message(message.chat.id, "Ввод не требуется")
bot.polling(none_stop=True, interval=0)
Файл database.db:
class Database:
def __init__(self, db_file):
self.db_file = db_file
def add_user(self, user_id):
with sqlite3.connect(self.db_file) as connection:
cursor = connection.cursor()
return cursor.execute('INSERT INTO users (user_id) VALUES(?)', (user_id,))
def user_exists(self, user_id):
with sqlite3.connect(self.db_file) as connection:
cursor = connection.cursor()
result = cursor.execute("SELECT * FROM users WHERE user_id = ?", (user_id,)).fetchall()
return bool(len(result))
def set_nickname(self, user_id, nickname):
with sqlite3.connect(self.db_file) as connection:
cursor = connection.cursor()
return cursor.execute("UPDATE users SET nickname = ? WHERE user_id = ?", (nickname, user_id,))
def get_signup(self, user_id):
with sqlite3.connect(self.db_file) as connection:
cursor = connection.cursor()
result = cursor.execute("SELECT signup FROM users WHERE user_id = ?", (user_id,)).fetchall()
for row in result:
signup = str(row[0])
return signup
def set_signup(self, user_id, signup):
with sqlite3.connect(self.db_file) as connection:
cursor = connection.cursor()
return cursor.execute("UPDATE users SET signup = ? WHERE user_id = ?", (signup, user_id,))
def nickname(self, user_id):
with sqlite3.connect(self.db_file) as connection:
cursor = connection.cursor()
result = cursor.execute("SELECT nickname FROM users WHERE user_id = ?", (user_id,)).fetchall()
for row in result:
nickname = str(row[0])
return nickname