python-3.x sqlite错误:无此列:(不管争论是什么)

nfs0ujit  于 2022-11-19  发布在  Python
关注(0)|答案(1)|浏览(106)

所以我正在使用sqlite和www.example.com来制作一个不和谐的机器人discord.py
这是给出错误的命令:

@bot.command()
@commands.has_permissions(administrator=True)
async def set_ip(ctx, arg=None):
    if arg == None:
        await ctx.send("You must type the IP adress next to the command!")
    elif arg.endswith('.aternos.me') == False:
        await ctx.send('IP must end with .aternos.me')
    elif ctx.guild.id == None:
        await ctx.send("This is a guild-only command!")
    else:
        ipas = None
        id = ctx.guild.id
        conn.execute(f'''DROP TABLE IF EXISTS guild_{id}''')
        conn.execute(f'''CREATE TABLE IF NOT EXISTS guild_{id} (
            ip TEXT NOT NULL
        )''')
        conn.execute(f'''INSERT INTO guild_{id} ("ip") VALUES ({arg})''')
        cursor = conn.execute(f'''SELECT ip FROM guild_{id}''')
        for row in cursor:
            ipas = row[0]
        if ipas == None:
            await ctx.send("Failed to set IP!")
            conn.execute(f'''DROP TABLE IF EXISTS guild_{id}''')
        else:
            await ctx.send(f"Your guild ip is now -> {ipas}")
            print("An ip has been set!")

我试图创建一个表,如果不存在的名称guild_(和discord服务器id),并检查它是否设置
错误为:操作错误:无此列:(参数)
sqlite给这个错误,我不能弄清楚,请帮助我。

vshtjzan

vshtjzan1#

您正在将列名作为字符串传递:

conn.execute(f'''INSERT INTO guild_{id} ("ip") VALUES ({arg})''')

应为:

conn.execute(f'''INSERT INTO guild_{id} (ip) VALUES ({arg})''')

相关问题