我正在開發 Discord 機器人,但不明白為什么會出現錯誤sqlite3.ProgrammingError: Incorrect number of bindings supplied.。資料庫中的資料是[('123', 'hello world!'), ('111', 'testing lolz')],當我以“123”作為 id 運行命令“搜索”時,機器人應該回復“hello world!”。我看過這篇文章,正如答案所說,我在 Sqlite3 代碼中使用了一個元組。以下是“搜索”命令的代碼:
@tree.command(name='search', description='search for a message by id!', guild=discord.Object(id=1025197159785693284))
async def search(intr: discord.Interaction, id: str):
res = cur.execute('SELECT message FROM messages WHERE id="(?)"', (id, )).fetchone()
await intr.response.send_message(f'message {id} is: {res[0]}')
con.commit()
uj5u.com熱心網友回復:
洗掉引數中的雙引號id="(?)":
res = cur.execute('SELECT message FROM messages WHERE id=(?)', (id, )).fetchone()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/514718.html
上一篇:如何在沒有SQLInjection的情況下動態插入SQLite?
下一篇:每年所有月份的年度總計
