【发布时间】: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