Discord.py Bot命令查看参数是否为int

Discord.py Bot命令查看参数是否为int,discord.py,Discord.py,现在,我有这段代码。我想让脚本知道hour是否为整数isnumeric()不起作用,因为它不计算负整数。谢谢你的回答 注意:这不在类中 @bot.command(pass_context=True) async def utc(ctx, hour): if(hour < 12 or hour > -12): timezones[ctx.message.author.id] = int(hour) else: ctx.send(&

现在,我有这段代码。我想让脚本知道
hour
是否为整数
isnumeric()
不起作用,因为它不计算负整数。谢谢你的回答

注意:这不在类中

@bot.command(pass_context=True)
async def utc(ctx, hour):
    if(hour < 12 or hour > -12):
            timezones[ctx.message.author.id] = int(hour)
    else:
        ctx.send("The UTC command is for telling Sterling how many hours away from UTC you are. You can also use negative numbers.")```
@bot.command(pass\u context=True)
异步定义utc(ctx,小时):
如果(小时<12或小时>-12):
时区[ctx.message.author.id]=int(小时)
其他:
ctx.send(“UTC命令用于告诉Sterling您离UTC还有多少小时。您也可以使用负数。”)```

默认情况下,命令以字符串形式接收参数,要将其转换为整数,可以使用discord.py s或手动将其转换为整数或浮点

使用转换器

async def utc(ctx,小时:int):
手动转换

async def utc(ctx,小时):
小时=整数(小时)
参考资料:

Try:
async def utc(ctx,hour:int):
使用函数注释