#How to properly specify parameters for slash commands?

1 messages · Page 1 of 1 (latest)

lusty skiff
#

I think I've been doing things wrong

@bot.slash_command(guild_ids=[getenv('DISCORD_GUILD')], description='AI Generate Image!')
@option(
    "prompt",
    description="Prompt",
    required=True,
    max_length=512,
)
@option(
    "seed",
    description="Image seed. -1 = random. (Default -1)",
    required=False,
    default='-1'
)
@option(
    "cfg_scale",
    description="High number will follow prompt more closely. (Default 7)",
    required=False,
    default='7'
)
@option(
    "negative_prompt",
    description="Negative Prompt, stuff you dont want. (Default none)",
    required=True,
    default='',
    max_length=512,
)
async def gen(
    ctx,
    prompt,
    negative_prompt,
    seed: int,
    cfg_scale,
):

Is there a better way than to have a @desert agatetion for each parameter that I want to include?

muted kayak
#

You can optionally type hint the parameters of your function

from discord.commands import Option
...
async def example(self, ctx, my_param : Option(...)):
#

.rtfm discord.Option

umbral valve
#
`required=true,`
#

should be True

umbral valve
muted kayak
#

It's an alternative way 🤷‍♂️

umbral valve
#

takes the same effort but you lose all IDE autocomplete and typehinting

#

btw you can have number inputs too

muted kayak
lusty skiff
#

i realised i edited something before copying

#

pos and negative prompt should have both been True

#

although setting negative prompt to require true doesnt work?

#

still shows up as a optional

muted kayak
#

Can you mix the order of required parmeters like that? I thought all required parameters needed to appear before the optional ones?

lusty skiff
#

maybe? ill try

#

doesnt seem to work when i moved it up

muted kayak
#

You have a default value on your parameter

#

which means it will automatically be required=False

lusty skiff
#

I see

#

I was only testing with the negative prompt so thats fine

#

now i just need to figure out how to add choices to another parameter

muted kayak
#

.rtfm discord.option.choices

dusk oysterBOT
#

Target not found, try again and make sure to check your spelling.

muted kayak
#

.rtfm discord.Option.choices

dusk oysterBOT
#

Target not found, try again and make sure to check your spelling.