【发布时间】:2021-11-14 10:54:16
【问题描述】:
我正在尝试为我的 discord.py 机器人创建一个欢迎系统,该系统必须是特定于服务器的。但是,当我尝试输入公会 ID 时,它会引发此错误。我对 MySQL 还很陌生,因此我们将不胜感激。
错误:
Traceback (most recent call last):
File "C:\Users\user-pc\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 994, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\user-pc\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 1448, in invoke
await ctx.invoked_subcommand.invoke(ctx)
File "C:\Users\user-pc\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 894, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\user-pc\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 176, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ProgrammingError: Failed processing format-parameters; Python 'guild' cannot be converted to a MySQL type
这是我的代码:
@welcome.command()
@has_permissions(administrator=True)
async def channel(self, ctx, channel:discord.TextChannel):
cursor.execute(f'SELECT channel_id FROM welcome WHERE guild_id = {ctx.guild.id}')
result = cursor.fetchone()
if result is None:
cursor.execute('INSERT INTO welcome (guild_id, channel_i) VALUES (%s,%s)', (ctx.guild, channel.id))
#values = (ctx.guild, channel.id)
db.commit()
#values = (ctx.guild.id, channel.id)
await ctx.send(f'Welcome channel has been set to {channel.mention}')
elif result is not None:
cursor.execute('UPDATE welcome SET channel_id = %s WHERE guild_id = %s', (channel.id, ctx.guild))
db.commit()
#values = (channel.id, ctx.guild.id)
await ctx.send(f'Welcome channel has been updated to {channel.mention}')
cursor.close()
db.close()
【问题讨论】:
标签: python mysql discord.py mysql-python