Expand description
§zaun-bot
The Rust SDK for Zaun bots: WebAssembly components that run inside a community’s own
zaun-host, in a sandbox, with only the permissions and capabilities the owner granted.
ⓘ
use zaun_bot::prelude::*;
#[derive(Default)]
struct Ping;
impl Bot for Ping {
fn commands(&mut self, _: &Config) -> Vec<ApplicationCommand> {
vec![SlashCommand::new("ping", "Check that the bot is alive").build()]
}
fn on_command(&mut self, ctx: Context, cmd: CommandData) {
if cmd.name == "ping" {
let _ = ctx.reply("pong");
}
}
}
export_bot!(Ping);The data shapes follow the Zaun specification §8.13–§8.14, which follow Discord’s
interaction model. The WIT world in wit/ is the source of truth.
Re-exports§
pub use bindings::zaun::bot::types;pub use bindings::zaun::bot::commands;pub use bindings::zaun::bot::community;pub use bindings::zaun::bot::dms;pub use bindings::zaun::bot::http;pub use bindings::zaun::bot::interactions;pub use bindings::zaun::bot::log;pub use bindings::zaun::bot::messages;pub use bindings::zaun::bot::storage;pub use bindings::zaun::bot::timers;pub use audio::Audio;pub use voice::Voice;
Modules§
- audio
- Low-level audio output (capability
voice): the bot writes the audio itself instead of naming tracks forVoice’s player. For synthesisers, text to speech, mixers, and formats the bot decodes on its own. Output only: bots never receive members’ audio. - bindings
- Generated bindings for the
zaun:bot/botworld. - mention
- Mentions: the text that shows them (
<@id>,<@&id>,@everyone) and what a message names in itsmentions. Zaun names mentions explicitly: the host never reads them from the text, so a message notifies only who itsMentionslist. - prelude
- Everything a typical bot needs.
- presence
- The bot’s presence and custom status, shown to every member next to its name: “Listening to lofi radio”, “🎵 Type /play”.
- voice
- Voice channels and music (capability
voice, ADR-0020).
Macros§
- export_
bot - Exports a
Bottype as the component’szaun:bot/botimplementation. - log_
info - Writes an
infoline to the bot’s log (zaun-host bot logs).
Structs§
- Action
Row - Builds a
types::ActionRow: up to 5 buttons, or one select. - Button
- Builds a
types::Button. - Command
Option Builder - Builds a
CommandOption. - Config
- The bot’s configuration: the keys its manifest declares in
[config], each with the value the owner set or else its default. Keys with neither are absent. Given toBot::on_startandBot::commandsat start and toBot::on_configon a change. - Container
- Builds a Components V2
types::Container. - Context
- The interaction being handled, without its data (handlers get the data separately).
- Embed
Builder - Builds an
Embed(§8.5). Pictures are attachment ids of the same message. - Event
Context - What an event handler can do: send, reply, react, delete and send direct messages. Every call is an ordinary command on the bot’s member, checked by the host.
- Modal
- Builds a
types::Modal: 1–5 labelled inputs and text blocks. - Reply
- Builds a
MessageBody.Reply::from("text")is the common case. - Section
- A Components V2 section: 1–3 text blocks with a button beside them.
- Slash
Command - Builds an
ApplicationCommand: a slash command, or a user or message context command. - SubCommand
- Builds a sub-command.
- SubCommand
Group - Builds a group of sub-commands (
/name group sub). - Text
Display - A Components V2 text block (markdown, ≤ 4 000 per message in all).
- Text
Input - Builds a
types::TextInputfor a modal.
Enums§
- Select
- Builds a select menu: string options or members, roles, mentionables or channels.
Traits§
- Bot
- A Zaun bot. Every handler has a no-op default; implement the ones you need.
- Options
- Reads option and modal values by name.
Functions§
- dispatch
- Calls the
Bothandler forevent. - text_
choice - A text
Choice(autocomplete results and fixed choices).