Discord.py 如何识别变量的类型?

Discord.py 如何识别变量的类型?,discord.py,Discord.py,我正在为discord创建一个清晰的命令,我希望这样,每当您输入字符串而不是int时,它都会在聊天中发送一条消息“请使用数字” 我尝试了如果isinstance(amount,int):但似乎不起作用 脚本V @client.command() 异步def清除(ctx,数量=1): role=discord.utils.get(ctx.guild.roles,name=“[+]Admin”) 如果角色在ctx.author.roles中: 如果isinstance(金额,整数): 打印('int

我正在为discord创建一个清晰的命令,我希望这样,每当您输入字符串而不是int时,它都会在聊天中发送一条消息“请使用数字”

我尝试了
如果isinstance(amount,int):
但似乎不起作用

脚本V

@client.command()
异步def清除(ctx,数量=1):
role=discord.utils.get(ctx.guild.roles,name=“[+]Admin”)
如果角色在ctx.author.roles中:
如果isinstance(金额,整数):
打印('int')
其他:
打印('str')
其他:
等待ctx.send(如果“您缺少权限”,请在=3后删除)```
>它可以识别是否为int值
```机器人准备好了。int```
>但不是字符串。
```机器人准备好了。
忽略命令清除中的异常:
回溯(最近一次呼叫最后一次):
文件“C:\Users\User\AppData\Local\Programs\Python\36\lib\site packages\discord\ext\commands\core.py”,第367行,实际转换
返回转换器(参数)
ValueError:基数为10的int()的文本无效:“Hello”
上述异常是以下异常的直接原因:
回溯(最近一次呼叫最后一次):
文件“C:\Users\User\AppData\Local\Programs\Python\36\lib\site packages\discord\ext\commands\bot.py”,第859行,在invoke中
等待ctx.command.invoke(ctx)
文件“C:\Users\User\AppData\Local\Programs\Python36\lib\site packages\discord\ext\commands\core.py”,第718行,在invoke中
等待自我准备(ctx)
文件“C:\Users\User\AppData\Local\Programs\Python36\lib\site packages\discord\ext\commands\core.py”,第682行,在prepare中
等待self.\u解析\u参数(ctx)
文件“C:\Users\User\AppData\Local\Programs\Python\36\lib\site packages\discord\ext\commands\core.py”,第596行,在(解析)参数中
转换=等待自我转换(ctx,参数)
文件“C:\Users\User\AppData\Local\Programs\Python36\lib\site packages\discord\ext\commands\core.py”,转换中第452行
return wait self.do_转换(ctx、转换器、参数、参数)
文件“C:\Users\User\AppData\Local\Programs\Python36\lib\site packages\discord\ext\commands\core.py”,第405行,在do\U转换中
返回等待自身。实际转换(ctx、转换器、参数、参数)
文件“C:\Users\User\AppData\Local\Programs\Python36\lib\site packages\discord\ext\commands\core.py”,第376行,实际转换
从exc引发BadArgument('将参数“{}”转换为“{}”失败)。格式(名称,param.name))
discord.ext.commands.errors.BadArgument:参数“amount”转换为“int”失败。
如果无法将输入转换为int,请使用和写入来处理引发的错误:

从discord.ext.commands导入参数

@client.command()
async def clear(ctx, amount: int=1):
    ...

@clear.error
async def clear_error(ctx, error):
    if isinstance(error, BadArgument):
        await ctx.send("Invalid integer argument.")
    else:
        raise error
如果无法将输入转换为int,请使用和写入来处理引发的错误:

从discord.ext.commands导入参数

@client.command()
async def clear(ctx, amount: int=1):
    ...

@clear.error
async def clear_error(ctx, error):
    if isinstance(error, BadArgument):
        await ctx.send("Invalid integer argument.")
    else:
        raise error