Skip to main content

Handler

Trait Handler 

Source
pub trait Handler: HandlerBounds + 'static {
    // Required method
    fn call(
        &self,
        ctx: Context,
    ) -> Pin<Box<dyn Future<Output = Response> + Send + '_>>;
}
Expand description

Trait for bot event handlers

Handlers use the extractor/responder pattern - they extract typed data from context and return types that implement IntoResponse.

§Example

// No parameters
async fn ping() -> &'static str {
    "Pong!"
}

// With extractors
async fn greet(user: User) -> String {
    format!("Hello, {}!", user.name)
}

// Multiple extractors
async fn info(user: User, channel: Channel) -> String {
    format!("User {} in channel {}", user.name, channel.id)
}

// Full context access when needed
async fn advanced(ctx: Context) -> Response {
    // ... complex logic
    Response::text("Done")
}

Required Methods§

Source

fn call( &self, ctx: Context, ) -> Pin<Box<dyn Future<Output = Response> + Send + '_>>

Handle the event and produce a response

Implementors§