Skip to main content

Crate zaun_bot

Crate zaun_bot 

Source
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 for Voice’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/bot world.
mention
Mentions: the text that shows them (<@id>, <@&id>, @everyone) and what a message names in its mentions. Zaun names mentions explicitly: the host never reads them from the text, so a message notifies only who its Mentions list.
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 Bot type as the component’s zaun:bot/bot implementation.
log_info
Writes an info line to the bot’s log (zaun-host bot logs).

Structs§

ActionRow
Builds a types::ActionRow: up to 5 buttons, or one select.
Button
Builds a types::Button.
CommandOptionBuilder
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 to Bot::on_start and Bot::commands at start and to Bot::on_config on a change.
Container
Builds a Components V2 types::Container.
Context
The interaction being handled, without its data (handlers get the data separately).
EmbedBuilder
Builds an Embed (§8.5). Pictures are attachment ids of the same message.
EventContext
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.
SlashCommand
Builds an ApplicationCommand: a slash command, or a user or message context command.
SubCommand
Builds a sub-command.
SubCommandGroup
Builds a group of sub-commands (/name group sub).
TextDisplay
A Components V2 text block (markdown, ≤ 4 000 per message in all).
TextInput
Builds a types::TextInput for 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 Bot handler for event.
text_choice
A text Choice (autocomplete results and fixed choices).