Expand description
Procedural macros for Composure, the Discord Interactions
framework. Use them through composure with its macros feature, which re-exports them:
composure::{app, command, group, component, modal, autocomplete, view, rsx, Choice, Modal}.
| Macro | |
|---|---|
#[app] | Collects Commands, Groups, handlers, Views and other Apps into the handler an Adapter serves |
#[command] | A Command from a function: Options from its parameters, the description from its doc comment |
#[group] | A Command whose subcommands are other Commands |
#[autocomplete] | Suggestions for an Option while the user types |
#[component] | Answers buttons and selects by custom_id prefix, with state in the custom_id |
#[modal] | Answers modal submits by custom_id prefix |
#[derive(Modal)] | A form shown as a modal, read back typed |
#[derive(Choice)] | An enum of fixed Choices |
rsx! | Markup for message and modal layouts |
#[view] | A layout rendered from Props, with inline handlers |
The Composure guide explains
each in depth; Views
lists every rsx! tag and attribute.
Macros§
- rsx
- Markup for a message or modal layout, as JSX: built-in tags are Discord’s components
(
<Container>,<Section>,<Text>,<Thumbnail>,<Gallery>/<Item>,<File>,<Separator>,<Row>,<Button>,<StringSelect>/<Option>,<UserSelect>, …; in a<Modal>:<Label>,<TextInput>,<RadioGroup>,<CheckboxGroup>,<Checkbox>,<FileUpload>), PascalCase tags are#[view]s. Evaluates to aView, or aModalViewfor a<Modal>root.
Attribute Macros§
- app
- 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. - autocomplete
- Defines an Autocomplete Handler from a function taking an optional leading
ctx: Ctxand what the user has typed so far asinput: &str. Attach it to a string, integer, or number Option with#[option("...", autocomplete = name)]. - command
- Defines a Command from a function. Parameters after an optional leading
ctx: Ctxbecome Options; the doc comment becomes the description. - component
- Defines a Component Handler from a function: it answers components whose
custom_idstarts with the prefix. Parameters after an optional leadingctx: ComponentCtxare state carried in thecustom_id(owned, serde-serializable), built with the generatedname::custom_id(..). - group
- Makes a unit struct a Group that routes to its subcommands. Groups can contain Groups one level deep.
- modal
- Defines a Modal Handler from a function: it answers submits of modals whose
custom_idstarts with the prefix. After an optional leadingctx: ModalCtxcomes the form (a#[derive(Modal)]type), then state carried in thecustom_id.name::show(..)is the modal response that opens the form. - view
- Defines a View: a layout rendered from its Props (the parameters, owned values), whose
rsx!s may hold inline handlers.