Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
729 views
in Technique[技术] by (71.8m points)

python - sqlite3.OperationalError: no such column: | Discord.py

When trying to make a change prefix command when I get this error when trying to change the current prefix:

sqlite3.OperationalError: no such column: e

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

Traceback (most recent call last):
  File "C:UsersachutAppDataRoamingPythonPython39site-packagesdiscordextcommandsot.py", line 903, in invoke
    await ctx.command.invoke(ctx)
  File "C:UsersachutAppDataRoamingPythonPython39site-packagesdiscordextcommandscore.py", line 859, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:UsersachutAppDataRoamingPythonPython39site-packagesdiscordextcommandscore.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: OperationalError: no such column: e

The code for the command is this:

@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))

Sorry if this could be an easy fix but I'm really bad at sqlite3. Thanks!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You just need single quotes around {newprefix} in the SQL command. With this the user won't need to add the quotes on Discord.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...