【发布时间】:2021-12-15 01:57:04
【问题描述】:
错误: TypeError:on_command_error() 缺少 1 个必需的位置参数:'ctx'
但唯一的问题是定义了 ctx:
@bot.event
async def on_command_error(self, error: commands.CommandError, ctx):
if isinstance(error, commands.CommandNotFound):
return
elif isinstance(error, commands.CommandOnCooldown):
message = f"This command is on cooldown. Please try again after {round(error.retry_after, 1)} seconds."
elif isinstance(error, commands.MissingPermissions):
message = "You are missing the required permissions to run this command!"
elif isinstance(error, commands.UserInputError):
message = "Something about your input was wrong, please check your input and try again!"
else:
message = "Oh no! Something went wrong while running the command!"
await ctx.send(message, delete_after=5)
await ctx.message.delete(delay=5)
还是我太傻了?
【问题讨论】:
-
没有看到对
on_command_error的实际调用很难说。但可能它被称为on_command_error(error, ctx) instead ofsomeobject.on_command_error(error, ctx). The argumentself` 隐含在第二个而不是第一个中。 -
也许您可以在问题中包含调用代码,以获得更好的答案
标签: python discord.py