Discord.py Slash 命令强制参数,而不是可选参数

Elm*_*Kao 6 python parameters discord discord.py

我正在尝试制作一个简单的命令,如果您不输入 2 个数字作为参数,它会选择 1 到 10 之间的随机数,问题是我希望需要 2 个参数并且不是可选的,如果您输入它工作正常: 在此输入图像描述

但是因为这 2 个参数都不是强制性的,所以你只能写 1,这使得它不能按我想要的方式工作,这将导致显示你选择的数字,而不是 2 个数字之间的随机数:

在此输入图像描述

如果需要的话,这是代码:

#COMANDO SLASH NUM
@cog_ext.cog_slash(name='Numero', description='Selecciona un numero aleatorio entre el 1 y el 10 si no se especifica ninguno')
async def numero(self, ctx, primero=1, ultimo=10):
    n = random.randint(int(primero),int(ultimo))
    await ctx.send(n)
Run Code Online (Sandbox Code Playgroud)

小智 1

用这个代替

@cog_ext.cog_slash(name='Numero', description='Selecciona un numero aleatorio entre el 1 y el 10 si no se especifica ninguno')
async def numero(self, ctx, primero: int = 1, ultimo: int = 10):
    n = random.randint(primero, ultimo)
    await ctx.send(n)
Run Code Online (Sandbox Code Playgroud)

上面的片段接受整数,并将参数默认为“=”符号后提供的数字。