我正在尝试使用SQLite数据库存储惩罚和警告历史记录,但出现错误,下面是代码:
@client.command()
@has_permissions(manage_messages=True)
async def warn(ctx, member : discord.Member, *, reason):
db = sqlite3.connect('punishments.sqlite')
cursor = db.cursor()
cursor.execute(f'''
INSERT INTO {ctx.message.guild.id}\n
VALUES({member.id}, {ctx.message.author.id}, {reason}, 'warning');
''')
db.commit()
cursor.close()
db.close()
await ctx.channel.send(f':white_check_mark: {member.mention} has been warned | {reason}')
await member.send(f'You were warned for {reason}.')
这是错误:
Ignoring exception in command warn:
Traceback (most recent call last):
File "C:\Users\myname\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 83, in wrapped
ret = await coro(*args, **kwargs)
File "c:/Users/myname/guardian/bot.py", line 127, in warn
cursor.execute(f'''
sqlite3.OperationalError: near "serverid": syntax error
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\myname\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\bot.py", line 892, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\myname\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 797, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\myname\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 92, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: OperationalError: near "serverid": syntax error
我已经重新命名了服务器的ID以及我的名字。
谢谢