我正試圖讓我的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')"/span>)
await ctx.send('Channel assigned.')
except:
await ctx.send('請先加入一個語音頻道。')
我在sqlite3檔案中創建了三行,分別是id(字串)、guild_id(字串)和theme(字串)。
我已經用這段代碼創建了它:
c.execute("CREATE TABLE channel_data(id STRING, guild_id STRING, theme STRING)"/span>)
但是,我得到的結果是這樣的:
Ignoring exception in command assign:
回溯(最近一次呼叫)。
檔案 "C:UserserickAppDataLocalProgramsPythonPython38libsite-packagesdiscordextcommandscore.py"/span>。
line 85, in wrapped
ret = await coro(*args, **kwargs)
檔案 "c:UserserickPython_VisualStudioCode???????? v2. py", line 55, in assign
c.execute("INSERT INTO channel_data VALUES (getid, getguild, '1')"/span>)
sqlite3.OperationalError: no such column: getid
上述例外是以下例外的直接原因。
回溯(最近一次呼叫)。
檔案 "C:UserserickAppDataLocalProgramsPythonPython38libsite-packagesdiscordextcommandsot. py", line 939, in invokeine 939, in invoke
await ctx.command.invoke(ctx) line 863, in invoke
檔案 "C:UserserickAppDataLocalProgramsPythonPython38libsite-packagesdiscordextcommandscore.py" 。
line 863, in invoke line 94, in wrapped
await injected(*ctx.args, **ctx.kwargs)
檔案 "C:UserserickAppDataLocalProgramsPythonPython38libsite-packagesdiscordextcommandscore.py"/span>, getid
line 94, in wrapped
raise CommandInvokeError(ex) from exc
discord.ext.command.errors.CommandInvokeError。命令引發了一個例外。OperationalError: no such column:
getid
請幫助:(
)uj5u.com熱心網友回復:
使用正確的語法來插入命令。
c.execute("INSERT INTO channel_data (id, guild_id, theme) VALUES (?, ?, ?)", (getid, getguild, '1' /span>)
你可以跳過列的部分(id, guild_id, theme),但這里的言辭可能很好。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/327117.html
標籤:
上一篇:重定向許多動態URL(301)
下一篇:為什么流暢的Hibernate.Sum在空表上使用時,會拋出InvalidOperationException?
