На стадии ввода имени в тг боте выдает ошибку:
for row in result:
TypeError: 'NoneType' object is not iterable
Код db:
import sqlite3
class Database:
def __init__(self, db_file):
self.connection = sqlite3.connect(db_file)
self.cursor = self.connection.cursor()
def add_user(self, user_id):
with self.connection:
return self.cursor.execute("INSERT INTO 'users' ('user_id') VALUES (?)",(user_id,))
def user_exist(self, user_id):
with self.connection:
result = self.cursor.execute("SELECT * FROM 'users' WHERE 'user_id' = ?",(user_id,)).fetchall()
return bool(len(result))
def set_nickname(self,user_id,nickname):
with self.connection:
return self.cursor.execute("UPDATE 'users' SET 'nickname' = ? WHERE 'user_id' = ?",(nickname,user_id))
def get_signup(self,user_id):
with self.connection:
result = self.cursor.execute("SELECT 'signup' FROM 'users' WHERE 'user_id' = ?", (user_id,)).fetchone()
for row in result:
signup = str(row[0])
return signup
def set_signup(self,user_id, signup):
with self.connection:
return self.cursor.execute("UPDATE 'users' SET 'signup' = ? WHERE 'user_id' = ?",(signup,user_id))
Код main:
import logging
from aiogram import Bot, Dispatcher, executor, types
import markups as nav
from db import Database
TOKEN = "5103821559:AAGL20hGYw8wUvBdu7u_vNeUQlhVxjmQIQs"
logging.basicConfig(level = logging.INFO)
bot = Bot(token = TOKEN)
dp = Dispatcher(bot)
db = Database('database.db')
@dp.message_handler(commands = ['start'])
async def start(message: types.Message):
if(not db.user_exist(message.from_user.id)):
db.add_user(message.from_user.id)
await bot.send_message(message.from_user.id, "Укажите ваш ник")
else:
await bot.send_message(message.from_user.id, "Вы уже зарегистрированы", reply_markup = nav.mainMenu)
@dp.message_handler()
async def bot_message(message: types.Message):
if message.chat.type == 'private':
if message.text == 'Профиль':
pass
else:
if db.get_signup(message.from_user.id) == "setnickname":
if len(message.text) > 15:
await bot.send_message(message.from_user.id, "Никнейм не должен превышать 15 символов")
elif '@' in message.text or '/' in message.text:
await bot.send_message(message.from_user.id, "Вы ввели запрещеный символ")
else:
db.set_nickname(message.from_user.id, message.text)
db.set_signup(message.from_user.id, "done")
await bot.send_message(message.from_user.id, "Регистрация прошла успешно", reply_markup = nav.mainMenu)
else:
await bot.send_message(message.from_user.id, "Я не понял")
if __name__ == "__main__":
executor.start_polling(dp, skip_updates = True)