Skip to main content

InteractionHandler

Trait InteractionHandler 

Source
pub trait InteractionHandler<S> {
    // Provided methods
    fn render_error(&self, error: &HandlerError) -> InteractionResponse { ... }
    fn command(
        &self,
        command: ApplicationCommandInteraction,
        _state: &S,
    ) -> impl Future<Output = Result<InteractionResponse, HandlerError>> + Send { ... }
    fn component(
        &self,
        _component: MessageComponentInteraction,
        _state: &S,
    ) -> impl Future<Output = Result<InteractionResponse, HandlerError>> + Send { ... }
    fn autocomplete(
        &self,
        _autocomplete: ApplicationCommandInteraction,
        _state: &S,
    ) -> impl Future<Output = Result<InteractionResponse, HandlerError>> + Send { ... }
    fn modal_submit(
        &self,
        _modal: ModalSubmitInteraction,
        _state: &S,
    ) -> impl Future<Output = Result<InteractionResponse, HandlerError>> + Send { ... }
}
Expand description

Answers Interactions; the one contract every Adapter talks to. S is the Adapter’s State.

An #[app] implements this by routing to what it lists. Implement it directly for full control. Every method has a default: unknown command, a “not handled” ephemeral message, or no autocomplete choices.

Futures are Send so Adapters can run each Interaction on any thread (ADR 0012); async fn in impls works as long as what it holds across .await is Send.

Provided Methods§

Source

fn render_error(&self, error: &HandlerError) -> InteractionResponse

The response a handler’s error is answered with: Adapters call it when dispatch fails, as Background Work does when deferred work fails. HandlerError::response by default; an #[app] uses its tree’s errors = .. ErrorRenderer.

Source

fn command( &self, command: ApplicationCommandInteraction, _state: &S, ) -> impl Future<Output = Result<InteractionResponse, HandlerError>> + Send

Answers a Command (chat input, user, or message); defaults to an unknown-command error

Source

fn component( &self, _component: MessageComponentInteraction, _state: &S, ) -> impl Future<Output = Result<InteractionResponse, HandlerError>> + Send

Answers a button click or select; defaults to a “not handled” ephemeral message

Source

fn autocomplete( &self, _autocomplete: ApplicationCommandInteraction, _state: &S, ) -> impl Future<Output = Result<InteractionResponse, HandlerError>> + Send

Autocomplete for command options. Defaults to no choices.

Source

fn modal_submit( &self, _modal: ModalSubmitInteraction, _state: &S, ) -> impl Future<Output = Result<InteractionResponse, HandlerError>> + Send

Answers a modal submit; defaults to a “not handled” ephemeral message

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§