Answer the question
In order to leave comments, you need to log in
How to select SQLite3 cell correctly?
servers_db = sqlite3.connect('servers.db')
servers_sql = servers_db.cursor()
servers_sql.execute("""CREATE TABLE IF NOT EXISTS servers (
id INTEGER PRIMARY KEY AUTOINCREMENT,
guild INT,
admin_channel INT
)""")
@bot.command()
async def admin_channel(ctx):
channel = ctx.message.channel.id
guild = int(ctx.message.guild.id)
servers_sql.execute(f"SELECT admin_channel FROM servers WHERE guild = '{guild}' ")
print(servers_sql.fetchone())
if servers_sql.fetchone() is None:
servers_sql.execute(f"INSERT WHERE guild = '{guild}' INTO servers(admin_channel) VALUES ('{channel}') ")
servers_sql.execute('SELECT * FROM servers')
rows = servers_sql.fetchall()
for row in rows:
print(row)
else:
#await channel.send('Бот уже был на этом сервере, ID добавлен')
print("again")
servers_db.commit()
Answer the question
In order to leave comments, you need to log in
Start by getting acquainted with the SQL syntax and specifically the INSERT command, it can be useful :) - www.sql-tutorial.ru/ru/book_operator_insert.html
servers_sql.execute(f"INSERT INTO servers(admin_channel) VALUES ('{channel}') WHERE guild = '{guild}' ")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question