pub trait Commands: Sized {
// Required methods
fn parse(
ctx: &Context,
command: &ApplicationCommandInteraction,
) -> Result<Self, ParseError>;
fn invoke<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 Context,
command_interaction: &'life2 ApplicationCommandInteraction,
) -> Pin<Box<dyn Future<Output = Result<(), InvocationError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
}Expand description
This trait should be derived for an enum with a variant for each command. This will implement the boilerplate to:
- Parse an interaction into a specific command based on the command name
- Delegate the invocation of a command to the specific enum variant
#[derive(Debug, Commands)]
enum BotCommands {
Hello(HelloCommand),
}Required Methods§
Sourcefn parse(
ctx: &Context,
command: &ApplicationCommandInteraction,
) -> Result<Self, ParseError>
fn parse( ctx: &Context, command: &ApplicationCommandInteraction, ) -> Result<Self, ParseError>
Parse an interaction into a specific command
Sourcefn invoke<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 Context,
command_interaction: &'life2 ApplicationCommandInteraction,
) -> Pin<Box<dyn Future<Output = Result<(), InvocationError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn invoke<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 Context,
command_interaction: &'life2 ApplicationCommandInteraction,
) -> Pin<Box<dyn Future<Output = Result<(), InvocationError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Invoke the command
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.