Answer the question
In order to leave comments, you need to log in
SQL how to fix error?
for guild in bot.guilds:
for member in guild.members:
if cursor.execute(f"SELECT id FROM users WHERE id = {member.id} AND server_id = {guild.id}").fetchone() is None:
cursor.execute(f"INSERT INTO users VALUES ('{member}', {member.id},0,0,{guild.id})")
else:
pass
connection.commit()
Answer the question
In order to leave comments, you need to log in
1. Do not generate queries through string formatting. Use placeholders. Starting with "the DB-API's parameter substitution"
2. If you need to insert a record if it doesn't exist, or do nothing if it does, read about INSERT ON CONFLICT DO NOTHING. Well, or about INSERT ON CONFLICT DO UPDATE, if you need to "insert a new one or update an existing one."
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question