python - 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))
谢谢!
解决方案
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))
推荐阅读
- spring - 遍历 Flux 项目并将它们添加到 Mono 对象
- arm - 在 ARM 管理程序 (EL2) 上
- javascript - 如何从不同的站点获取 Json 数据
- python - Python 本地包
- python - 如何从特定的col开始读取excel数据
- python - sqlite3.OperationalError:数据库被锁定。添加最后 2 个字段后出现问题。怎么解决?
- python - Django无法弄清楚如何使用外键
- ios - 手机锁定时如何在IOS上接收和发送蓝牙数据
- swift - 如何在 SCADE 中将文件声明为参考
- python - 有没有办法可以在 kivy 中使用 gridLayout 将文本放置在屏幕顶部?