尝试使用 Python 和 Sqlite3 时出现 NoneType 错误
I am getting a NoneType error when trying to work with Python and Sqlite3
cursor.execute(f"SELECT user_id, Class, Health, Mana, Defense, Maxmana, Maxhealth, Attack, Critical FROM savefile WHERE user_id = '{message.author.id}'")
result1 = cursor.fetchone()
classs = int(result1[1]); health = int(result1[2]); mana = int(result1[3]); defense = int(result1[4]); attack = int(result1[7]); critical = int(result1[8])
sql = "UPDATE savefile SET Class = ? AND SET Health = ? AND SET Mana = ? AND SET Defense = ? AND SET Maxmana = ? AND SET Maxhealth = ? AND SET Attack = ? AND SET Critical = ? WHERE user_id = ?"
val = (classs + classplus, str(message.author.id),
health + healthplus, str(message.author.id),
mana + manaplus, str(message.author.id),
defense + defenseplus, str(message.author.id),
attack + attackplus, str(message.author.id),
critical + criticalplus, str(message.author.id))
cursor.execute(sql, val)
db.commit()
这是我正在使用的代码块。我目前正在制作一个不和谐的机器人,并将其他几个命令添加到一个列中。但是,在 "classs = ..." 行上,我上面显示的代码中的第三行(有意添加 S)出现此错误:
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
一般来说,我对使用 sqlite 比较陌生,不明白为什么会这样。我的其他机器人命令中有与此类似的代码,但不明白为什么这特别不起作用。提前感谢您的帮助!
其中一个结果 (result1[i]) 很可能是 NoneType,这意味着没有从数据库中检索到数据:
classs = int(result1[1]); health = int(result1[2]); mana = int(result1[3]); defense = int(result1[4]); attack = int(result1[7]); critical = int(result1[8])
cursor.execute(f"SELECT user_id, Class, Health, Mana, Defense, Maxmana, Maxhealth, Attack, Critical FROM savefile WHERE user_id = '{message.author.id}'")
result1 = cursor.fetchone()
classs = int(result1[1]); health = int(result1[2]); mana = int(result1[3]); defense = int(result1[4]); attack = int(result1[7]); critical = int(result1[8])
sql = "UPDATE savefile SET Class = ? AND SET Health = ? AND SET Mana = ? AND SET Defense = ? AND SET Maxmana = ? AND SET Maxhealth = ? AND SET Attack = ? AND SET Critical = ? WHERE user_id = ?"
val = (classs + classplus, str(message.author.id),
health + healthplus, str(message.author.id),
mana + manaplus, str(message.author.id),
defense + defenseplus, str(message.author.id),
attack + attackplus, str(message.author.id),
critical + criticalplus, str(message.author.id))
cursor.execute(sql, val)
db.commit()
这是我正在使用的代码块。我目前正在制作一个不和谐的机器人,并将其他几个命令添加到一个列中。但是,在 "classs = ..." 行上,我上面显示的代码中的第三行(有意添加 S)出现此错误:
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
一般来说,我对使用 sqlite 比较陌生,不明白为什么会这样。我的其他机器人命令中有与此类似的代码,但不明白为什么这特别不起作用。提前感谢您的帮助!
其中一个结果 (result1[i]) 很可能是 NoneType,这意味着没有从数据库中检索到数据:
classs = int(result1[1]); health = int(result1[2]); mana = int(result1[3]); defense = int(result1[4]); attack = int(result1[7]); critical = int(result1[8])