【发布时间】:2021-11-13 02:15:32
【问题描述】:
我正在尝试让我的 Discord 机器人在用户加入时自动加入语音频道。
为此,机器人首先获取服务器的 ID 和用户所在的语音通道,然后将其保存到 sqlite3 文件中。
下面是我的代码:
global conn
global c
conn = sqlite3.connect('test.db')
c = conn.cursor()
@bot.command()
async def assign(ctx):
try:
global getid
global getguild
getid = ctx.author.voice.channel.id
getguild = ctx.author.guild.id
c.execute ("INSERT INTO channel_data VALUES (getid, getguild, '1')")
await ctx.send('Channel assigned.')
except:
await ctx.send('Please join a voice channel first.')
我在我的 sqlite3 文件中创建了三行,分别是 id(字符串)、guild_id(字符串)和 theme(字符串) .
我已经使用以下代码创建了它:
c.execute("CREATE TABLE channel_data(id STRING, guild_id STRING, theme STRING)")
但是,这是我得到的:
Ignoring exception in command assign:
Traceback (most recent call last):
File "C:\Users\erick\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py",
line 85, in wrapped
ret = await coro(*args, **kwargs)
File "c:\Users\erick\Python_VisualStudioCode\데이터베이스\리타 v2.py", line 55, in assign
c.execute("INSERT INTO channel_data VALUES (getid, getguild, '1')")
sqlite3.OperationalError: no such column: getid
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\erick\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\bot.py", line 939, in invokeine 939, in invoke
await ctx.command.invoke(ctx) line 863, in invoke
File "C:\Users\erick\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py",
line 863, in invoke line 94, in wrapped
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\erick\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", getid
line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: OperationalError: no such column:
getid
请帮忙:(
【问题讨论】:
标签: python sqlite discord.py