discordnextcord

How to add a description for slash command arguments in nextcord?


I've been trying to add a description for my slash command arguments in nextcord, I can't seem to firgure out how.

This is my code:

@__Bot__.slash_command(description="Retrieve a Quran verse.")
async def hello(interaction: nextcord.Interaction, start: str, verse: str, end: Optional[int]):
    VerseCommand = [(start, verse, end)]
....

This is what I am hoping to achieve. "Page Number"

I tried using from nextcord import Options but it doesn't work.


Solution

  • There are multiple ways to achieve this.

    Option 1 - SlashOption

    You can add additional settings for slash command options including the description, choices, and value ranges by setting a default value using the SlashOption class. See the Application Command Docs and more examples.

    @__Bot__.slash_command(description="Retrieve a Quran verse.")
    async def hello(
        interaction: nextcord.Interaction,
        start: str = nextcord.SlashOption(description="Enter Start")
        verse: str = nextcord.SlashOption(description="Enter Verse"),
        end: Optional[int] = nextcord.SlashOption(description="Enter End"),
    ):
        VerseCommand = [(start, verse, end)]
    

    Option 2 - Numpy-style, Google-style, or Sphinx-style docstrings

    You can find examples of each supported style in PR 480.

    Example using Google-style docstrings (replace "Enter start value", "Enter verse value", etc with your descriptions)

    @__Bot__.slash_command(description="Retrieve a Quran verse.")
    async def hello(interaction: nextcord.Interaction, start: str, verse: str, end: Optional[int]):
        """
        Your command description goes here
    
        Args:
            interaction: The interaction object
            start: Enter start value
            verse: Enter verse value
            end: Enter end value
        """
        VerseCommand = [(start, verse, end)]
    

    Example using Numpy-style docstrings:

    @__Bot__.slash_command(description="Retrieve a Quran verse.")
    async def hello(interaction: nextcord.Interaction, start: str, verse: str, end: Optional[int]):
        """
        Your command description goes here
    
        Parameters
        ----------
        interaction:
            The interaction object
        start:
            Enter start value
        verse:
            Enter verse value
        end:
            Enter end value
        """
        VerseCommand = [(start, verse, end)]
    

    Example using Sphinx-style docstrings:

    @__Bot__.slash_command(description="Retrieve a Quran verse.")
    async def hello(interaction: nextcord.Interaction, start: str, verse: str, end: Optional[int]):
        """
        Your command description goes here
    
        :param interaction: The interaction object
        :param start: Enter start value
        :param verse: Enter verse value
        :param end: Enter end value
        """
        VerseCommand = [(start, verse, end)]