pub trait ApplicationCommandInteractionHandler {
// Required method
fn invoke<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 Context,
command: &'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 provides a function to receive and respond to slash command interactions.
Typically you will want to respond using create_interaction_response - see the serenity
docs for more info.
#[async_trait]
impl ApplicationCommandInteractionHandler for HelloCommand {
async fn invoke(
&self,
ctx: &Context,
command: &ApplicationCommandInteraction,
) -> Result<(), InvocationError> {
let nickname = self.user.member.as_ref().map(|pm| pm.nick.as_ref()).flatten();
let greeting = if let Some(nick) = nickname {
format!("Hello {} aka {}", self.user.user.name, nick)
} else {
format!("Hello {}", self.user.user.name)
};
command
.create_interaction_response(&ctx.http, |response| {
response
.kind(InteractionResponseType::ChannelMessageWithSource)
.interaction_response_data(|message| message.content(greeting))
})
.await
.map_err(|_| InvocationError)
}
}Required Methods§
Sourcefn invoke<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 Context,
command: &'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: &'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