首页 > 解决方案 > Discord.py 检查参数是否是某些值之间的数字

问题描述

我们有一个非常简单的 discord 脚本,用户可以在其中输入 !dino 1234

该脚本将返回http://www.url.com/images/1234.png

作为 python 和 discord.py 的新手,我不知道如何检查输入的参数是否在 1-100(图片数量)之间,如果是,则只返回 url。

所以如果 arg > 0 & <101

bot = commands.Bot(command_prefix='!')
@bot.command(name='dino')
async def dino(ctx,arg :int):
 
   await ctx.send('http://www.url.com/images/{}.png'.format(arg))  
   await ctx.send('Picture #{}'.format(arg))

谢谢!

标签: pythondiscord.py

解决方案


bot = commands.Bot(command_prefix='!')
@bot.command(name='dino')
async def dino(ctx, arg:int):
    if 0 <= arg <= 100: #This will check the number is between 0 and 100.
        await ctx.send('http://www.url.com/images/{}.png'.format(arg))  
        await ctx.send('Picture #{}'.format(arg))

推荐阅读