Python 如何从discord.py的错误中获取参数?

Python 如何从discord.py的错误中获取参数?,python,discord.py,Python,Discord.py,我想得到一个如下图所示的参数: 我的代码: class Admin(commands.Cog): def __init__(self, bot): self.bot = bot @commands.command() async def purge(self, ctx, amount: int): await ctx.channel.purge(limit=amount+1) @purge.error async de

我想得到一个如下图所示的参数:

我的代码:

class Admin(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.command()
    async def purge(self, ctx, amount: int):
        await ctx.channel.purge(limit=amount+1)

    @purge.error
    async def purge_error(self, ctx, error):
        if isinstance(error, commands.MissingRequiredArgument):
            await ctx.send('Please enter a number.')
        elif isinstance(error, commands.BadArgument):
            await ctx.send('This is not a number.')
我该怎么做呢?

没有像其他异常一样作为
参数
属性传递

如果您试图获取
MissingRequiredArgument
的参数名,您只需使用该属性和

否则,
BadArgument
通常会被传递一条消息。是一个包含
参数的字符串。name
的形式为
'转换为参数“{}.”失败。format(name,param.name)
其中
name
是转换器名称,
param
参数
,并解析图像中的bot获取它的方式。在这种情况下,可以通过将
BadArgument
强制转换为字符串或作为异常的
args
属性返回的元组中的第一个也是唯一的参数来获取此消息。有关更多详细信息,请参阅

但是请注意,
BadArgument
可能是由于整数转换以外的原因而引发的,并且具有不同或没有消息,例如布尔转换器、不一致转换器、自定义转换器等。

不会传递其他异常,如
param
属性

如果您试图获取
MissingRequiredArgument
的参数名,您只需使用该属性和

否则,
BadArgument
通常会被传递一条消息。是一个包含
参数的字符串。name
的形式为
'转换为参数“{}.”失败。format(name,param.name)
其中
name
是转换器名称,
param
参数
,并解析图像中的bot获取它的方式。在这种情况下,可以通过将
BadArgument
强制转换为字符串或作为异常的
args
属性返回的元组中的第一个也是唯一的参数来获取此消息。有关更多详细信息,请参阅


但是请注意,
BadArgument
可能是由于整数转换以外的原因而引发的,并且可能会有不同或没有消息,例如布尔转换器、不一致转换器、自定义转换器等。

如果您只是发送了错误,则参数“amount”将
转换为“int”失败.
aka lib在后端为您处理它。不是您想要的确切格式,但似乎这是最简单的解决方案。如果您只是发送了错误,则参数“amount”转换为“int”失败。aka lib会在后端为您处理它。不是你想要的确切格式,但似乎这是最简单的解决方案。