SubCommandGroup

Trait SubCommandGroup 

Source
pub trait SubCommandGroup: Sized {
    // Required methods
    fn parse(
        option: Option<&ApplicationCommandInteractionDataOption>,
    ) -> Result<Self, ParseError>;
    fn register_sub_options(
        option: &mut CreateApplicationCommandOption,
    ) -> &mut CreateApplicationCommandOption;
}
Expand description

This trait provides the functions necessary to parse and register a subcommand group for a slash command.

For most use cases:

// 1. Create the "leaf" subcommands as normal (see SubCommand docs)
// 2. Create an enum with a variant for each subcommand in the subcommand group and derive the
// SubCommandGroup and ApplicationCommandInteractionHandler traits:

/// A test command to show subcommands
#[derive(Debug, SubCommandGroup, ApplicationCommandInteractionHandler)]
#[name = "test sub command group"]
enum TestSubCommandGroup {
    /// The first subcommand
    #[name = "one"]
    One(TestSubCommandOne),

    /// The second subcommand
    #[name = "two"]
    Two(TestSubCommandTwo),
}

// 3. Create an enum with a variant for each subcommand / subcommand group and derive the
// Command and ApplicationCommandInteractionHandler traits:

/// A test command to show subcommands
#[derive(Debug, Command, ApplicationCommandInteractionHandler)]
#[name = "test"]
enum TestCommand {
    /// The subcommand group
    #[subcommandgroup]
    #[name = "group"]
    Group(TestSubCommandGroup),

    /// A regular subcommand
    #[name = "three"]
    Three(TestSubCommandThree),
}

Note that you can mix subcommands and subcommand groups in a command as in the example above.

Required Methods§

Source

fn parse( option: Option<&ApplicationCommandInteractionDataOption>, ) -> Result<Self, ParseError>

Try to parse this from a command option

Source

fn register_sub_options( option: &mut CreateApplicationCommandOption, ) -> &mut CreateApplicationCommandOption

Register any sub options for this subcommand group

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§