discord.pyslashnextcord

Multiple SlashOptions Nextcord


I am trying to to create a command that that allows a user to select multiple options and then put them in an embed. So far I have been able to do this with one option but I want to do it with more as well. Is there a way to add multiple SlashOptions to a slash command and if so how might it be done. Thank you for all your help.

Here is what I currently have

async def announce(interaction: Interaction, buysell:str = SlashOption(
        name="bto-stc",
        choices={"BTO": "BTO", "STC": "STC"}),
        stock:str,):
    embed = nextcord.Embed(description=f"**Options Entry**", color=0x00FF00)
    embed.add_field(name=f"** [🎟️] Contract:** *{buysell}* *{stock}*", value="⠀", inline=False)

    await interaction.response.send_message(embed=embed, ephemeral=False)```

Here is what I would like the end product to look like. 
https://i.sstatic.net/9SmIK.png

Solution

  • Your stock argument must be before your choices argument as for Python this argument is and optional argument and you can't have required arguments before optionals ones.

    Also if you don't want your buysell argument to be optional you need to add a required argument set to True in your SlashOption object. And in your case you can also replace the choices argument in the SlashOptionobject by a list as the choices and the data you want from them are the same.

    Example:

    async def announce(interaction: Interaction, stock:str, buysell:str = SlashOption(
            name="bto-stc",
            choices=["BTO", "STC"],
            required=True)):
    
        embed = nextcord.Embed(description=f"**Options Entry**", color=0x00FF00)
        embed.add_field(name=f"** [🎟️] Contract:** *{buysell}* *{stock}*", value="⠀", inline=False)
    
        await interaction.response.send_message(embed=embed, ephemeral=False)