【问题标题】:discord py SQLite warning command db errordiscord py SQLite 警告命令 db 错误
【发布时间】:2021-09-06 03:01:41
【问题描述】:
async def warnings(ctx,*,arg1):
    #await ctx.send('Warning {} \nreason {}'.format(arg1))
    print(arg1)
    name=arg1
    db.execute('SELECT name FROM warnings WHERE name = "?"', (name))
    conn.commit()
    warnings = db.fetchall()
    print(warnings)

我试图在 sqlite 中为用户的警告进行搜索。但我有这个错误,我该如何解决这个问题 我做错了什么?

Traceback (most recent call last):
  File "C:\Python38\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "d:/_User/Desktop/Development/shop.py", line 279, in warnings
    db.execute('SELECT name FROM warnings WHERE name = "?"', "{name}")
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 0, and there are 6 supplied.

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

Traceback (most recent call last):
  File "C:\Python38\lib\site-packages\discord\ext\commands\bot.py", line 903, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Python38\lib\site-packages\discord\ext\commands\core.py", line 859, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Python38\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ProgrammingError: Incorrect number of bindings supplied. The current statement uses 0, and there are 6 supplied.

【问题讨论】:

    标签: python sql sqlite discord discord.py


    【解决方案1】:

    First result on Google 是另一个回答您问题的 SO 帖子。您需要通过在末尾添加逗号来使参数成为元组而不是字符串。

    (name,)
    

    在询问之前尽量自己研究问题,这不应该超过 5 秒。

    【讨论】:

      猜你喜欢
      • 2021-07-03
      • 2019-03-07
      • 1970-01-01
      • 2021-05-31
      • 2021-05-22
      • 2021-06-02
      • 2021-02-27
      • 1970-01-01
      • 2020-07-09
      相关资源
      最近更新 更多