TypeError: '<=' not supported between instances of 'type' and 'int'```

TypeError: '<=' not supported between instances of 'type' and 'int'```

此代码:

@client.command()
async def history(ctx,user:discord.User,amount= int):
    async for message in user.history(limit= amount):
       await ctx.channel.send(message.content)

出现这个错误

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: '<=' not supported between instances of 'type' and 'int'

如何解决?

您已将 amount 的默认值声明为 class int,而不是整数 。据推测,你要么意味着要成为一个打字注释 amount: int (你需要传递一个实际的整数参数,但你没有这样做),或者你应该分配一个实际的整数值作为默认值,例如amount=10 或任何有意义的默认限制。

照原样,user.history 最终收到 limit 参数的 int,而不是实际的整数值,事情开始走下坡路。

amount=int 更改为 amount: int

它被解释为默认参数而不是类型提示。