#Unable to use Required Parameter in Option class

1 messages · Page 1 of 1 (latest)

gray juniper
#

Hi, sorry for the bother but I seem to be getting an error when I try to use the Option class for my commands, I get an error whenever I use the required parameter. Here's the code that I wrote that has the issue:

@bot.command(description="Launches the Gmod Server if it's not running")
async def launchgmodserver(ctx, 
                           maxplayers: discord.SlashCommandOptionType.integer, 
                           mapId: discord.Option(input_type = str, name = "map", channel_type = None, required = False), 
                           workshopid: discord.SlashCommandOptionType.integer):
    await ctx.respond("I still don't work ya numpty")
    pass

and when I run it with the current code. It gives me this error:

discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In 0.options.2: Required options must be placed before non-required options

But, when I look at the documentation of the Option class, I don't see what Required options I'm missing. Otherwise, when I run the code without the required = False, the program runs without a hitch. I'm not sure what I'm doing wrong but I would be grateful for any help

gray juniper
#

I've updated the Library to the current Dev library thinking that it would help but I still have the same issue. I also changed the order of the parameters based on a message that was deleted to see if that changed the result but the Error still appears with the same response. At this point I'm not sure what I'm doing wrong.

uncut echo
#

Think you have to set maxplayers param to required=true

gray juniper
#

I just realised that, after reading what you posted, what the other person meant to say wasn't rearranging the Option class initiator parameters but the Function parameters of my command. After having done that(putting mapId last), it now works. Thank you for the help