sqlite3.OperationalError:没有这样的列:|不和谐.py

时间:2021-01-01 04:10:12

标签: python sqlite discord discord.py discord.py-rewrite

当我尝试更改当前前缀时出现此错误时尝试进行更改前缀命令时:

sqlite3.OperationalError: no such column: e

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\achut\AppData\Roaming\Python\Python39\site-packages\discord\ext\commands\bot.py", line 903, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\achut\AppData\Roaming\Python\Python39\site-packages\discord\ext\commands\core.py", line 859, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\achut\AppData\Roaming\Python\Python39\site-packages\discord\ext\commands\core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: OperationalError: no such column: e

命令的代码是这样的:

@client.command()
@commands.has_permissions(manage_guild=True)
async def change_prefix(ctx, newprefix: str):
    if len(newprefix) > 5:
        await ctx.send("The server prefix cannot be less than 5 characters in length!")

    else:
        cursor.execute(f"UPDATE guilds SET prefix = {newprefix} WHERE serverid = {ctx.guild.id}")
        connection.commit()
        await ctx.send(embed = discord.Embed(title = f"Prefix Changed to `{newprefix}`",description = f"The bot's server prefix was just changed to `{newprefix}`!", colour=0x04ff00))

对不起,如果这可以是一个简单的解决方案,但我在 sqlite3 方面真的很糟糕。谢谢!

1 个答案:

答案 0 :(得分:0)

您只需要在 SQL 命令中用单引号将 {newprefix} 括起来。有了这个,用户就不需要在 Discord 上添加引号了。

cursor.execute(f"UPDATE guilds SET prefix = '{newprefix}' WHERE serverid = {ctx.guild.id}")