Skip to content

Add sub-command example to docs #40

@colcrunch

Description

@colcrunch

I will start by saying I am very new to Elixir, so this may not be a problem to those more comfortable with the language. Anyways, I was trying to add some sub-commands earlier, and got quite confused when trying to get them to work.

They are mentioned a few times in the Nosedrum documentation, such as in the specs of Nosedrum.ApplicationCommand's option struct, or the docs for the application_command_path struct on Nosedrum.Storage, but how one would actually use them in the context of Nosedrum is fairly opaque.

Including the options method and command method(s) of a module that implements subcommands could prove very useful.

Here is an example from my testing:

  @impl true
  def options() do
    [
      %{
        type: :sub_command,
        name: "sub_test",
        description: "This is a subcommand"
      },
      %{
        type: :sub_command,
        name: "sub_test2",
        description: "This is another subcommand"
      }
    ]
  end

  @impl true
  def command(%Interaction{data: %{options: [%{name: "sub_test"}]}}), do: [content: "XX"]
  def command(%Interaction{data: %{options: [%{name: "sub_test2"}]}}), do: [content: "YY"]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions