Discord.py Slash commands mandatory parameters, not optionals

Viewed 1237

I'm trying to make a simple commands that if you don't enter 2 numbers as arguments, it selects a random number between 1 and 10, the problem is that I want to be needed 2 parameters and not being optional, If you put it it works fine: enter image description here

But because neither of the 2 parameters are mandatory, you can write only 1 which makes it work not how I want, this will result in showing the number you choose instead of a random between 2 numbers:

enter image description here

Here is the code if needed:

#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)
1 Answers

Use this instead

@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)

The snipped above accepts integers and defaults the arguments to the number provided after the "=" symbol.

Related