Skip to main content

app

Attribute Macro app 

Source
#[app]
Available on crate feature macros only.
Expand description

Collects Routes into an App, the handler an Adapter serves. See Getting started and Platforms. Makes a unit struct an App: the Interaction Handler routing to the Commands, Groups, Component and Modal Handlers, Views and other Apps listed in handlers(..), in any mix and order.

ⓘ
/// Everything the bot serves
#[app(handlers(ping, echo, Admin, counter_click, on_feedback, Card, Moderation),
      events = MyEvents, errors = render_error)]
pub struct Bot;
  • Implements InteractionHandler (for every State all listed items accept), EventHandler and CommandSetDefinition (for Sync); Bot.with_fallback(handler) sends what nothing listed handles (components, modals, autocomplete, commands) to handler
  • Apps nest: a module can declare its own #[app] next to its handlers and be listed in the root one
  • events = MyEvents (a unit struct implementing EventHandler): handles Webhook Events; at most one App in a tree sets it
  • errors = render_error (a fn(&HandlerError) -> InteractionResponse, an ErrorRenderer): the response handler errors are answered with, here and from deferred work, instead of HandlerError::response’s ephemeral text; at most one App in a tree sets it, and the root uses it for the whole tree

Two Commands with the same name and type, two handlers with the same custom_id prefix, more Commands than Discord allows in one Scope, a placed sub-View with handlers that is not listed, or two Apps setting events (or errors) fail to compile.