我正在制作一個(gè)不和諧的機(jī)器人。我嘗試使用 SQLite3 數(shù)據(jù)庫來增加我的機(jī)器人的經(jīng)濟(jì)性。但是當(dāng)我創(chuàng)建專欄時(shí)出現(xiàn)錯(cuò)誤:cursor.execute(f"INSERT INTO users VALUES ('{member}', {member.id}, 30, 0, 0, 1, {guild.id})")sqlite3.OperationalError: near "s": syntax error而且,這是代碼:@client.eventasync def on_ready(): cursor.execute("""CREATE TABLE IF NOT EXISTS users ( name TEXT, id INT, cash BIGINT, rep INT, xp INT, lvl INT, server_id INT )""") for guild in client.guilds: for member in guild.members: if cursor.execute(f"SELECT id FROM users WHERE id = {member.id}").fetchone() is None: cursor.execute(f"INSERT INTO users VALUES ('{member}', {member.id}, 30, 0, 0, 1, {guild.id})") else: pass connection.commit()
1 回答

慕工程0101907
TA貢獻(xiàn)1887條經(jīng)驗(yàn) 獲得超5個(gè)贊
代碼注入錯(cuò)誤!member
考慮一下如果字符串化是會(huì)發(fā)生什么Foo's Bar
。你最終會(huì)執(zhí)行
INSERT?INTO?users?VALUES?('Foo's?Bar... ????????????????????--?^?Syntax?error
我相信
cursor.execute(f"SELECT?id?FROM?users?WHERE?id?=?{member.id}") cursor.execute(f"INSERT?INTO?users?VALUES?('{member}',?{member.id},?30,?0,?0,?1,?{guild.id})")
應(yīng)該
cursor.execute("SELECT?id?FROM?users?WHERE?id?=??",?(?member.id,?)) cursor.execute("INSERT?INTO?users?VALUES?(?,??,?30,?0,?0,?1,??)", ???(?str(member),?member.id,?guild.id?)?)
添加回答
舉報(bào)
0/150
提交
取消