【问题标题】:Trying to add custom prefixes to my discord.py bot using sqlite3尝试使用 sqlite3 向我的 discord.py 机器人添加自定义前缀
【发布时间】:2021-06-15 08:53:38
【问题描述】:

这是我的代码:

def get_prefix(bot, message):
    cursor.execute('SELECT prefix FROM prefijos WHERE id = ?', (message.guild.id,))
    prefix = cursor.fetchone()
    db.commit()
    return when_mentioned_or(prefix)(bot, message)

bot = commands.Bot(command_prefix=get_prefix)

但是这段代码没有按预期工作。只有当我提到机器人时它才有效,但没有自定义前缀。正如我所说,我使用 sqlite3 作为存储前缀的数据库。

我遇到的错误(当我使用前缀时)是这样的:

    raise TypeError("Iterable command_prefix or list returned from get_prefix must "
TypeError: Iterable command_prefix or list returned from get_prefix must contain only strings, not tuple

如果我从“cursor.execute...”部分删除逗号,则会出现此错误(这是来自 sqlite 的错误)

    cursor.execute('SELECT prefix FROM prefijos WHERE id = ?', (message.guild.id))
ValueError: parameters are of unsupported type

如何修复此代码? 谢谢。

【问题讨论】:

    标签: python sqlite discord discord.py


    【解决方案1】:

    cursor.fetchone() 返回一个列表或元组,即使该行只包含一件事。试试

    prefix=cursor.fetchone()[0]
    

    【讨论】:

      猜你喜欢
      • 2021-07-19
      • 1970-01-01
      • 2021-03-31
      • 2021-09-26
      • 2021-06-19
      • 2018-12-01
      • 2021-02-12
      • 2021-04-04
      • 2021-10-07
      相关资源
      最近更新 更多