Skip to content

zaun-bot 0.2.0

Generated from rustdoc for zaun_bot 0.2.0. Browse the full rustdoc HTML.

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 the protocol–the protocol, which follow Discord’s interaction model. The WIT world in wit/ is the source of truth.

Item Summary
mention::EVERYONE The text that shows @everyone.
mention::MAX_MEMBERS Most members one message may mention (spec the protocol).
mention::MAX_ROLES Most roles one message may mention (spec the protocol).
Item Summary
presence::ActivityType “Playing {name}”, “Streaming {name}”, “Listening to {name}”, “Watching {name}”, “Competing in {name}”, or free text (custom).
audio::AudioFormat How the bot’s audio is encoded.
bindings::zaun::bot::types::ButtonStyle components Button styles 1-5; premium (6) is not supported.
prelude::ChoiceValue
bindings::zaun::bot::types::CommandEntry
bindings::zaun::bot::types::CommandKind application commands Type 1, 2, 3.
bindings::zaun::bot::types::Component A top-level message component. Without components-v2 only action-row is allowed.
bindings::zaun::bot::types::ContainerChild
bindings::zaun::bot::types::DefaultValueKind
bindings::zaun::bot::types::EntityKind Types 5 (user), 6 (role), 7 (mentionable), 8 (channel).
prelude::Event The events a bot asked for in its manifest (events: wire types, groups such as messages, members, dms, or *). Anything without a typed case arrives as other with the ev
bindings::zaun::bot::http::HttpError
bindings::zaun::bot::types::InteractionData
bindings::zaun::bot::types::LabelChild
bindings::zaun::bot::log::Level
voice::LoopMode What happens when a track ends: go on (off), play it again (track), or put it at the end of the queue (queue).
bindings::zaun::bot::types::ModalItem
bindings::zaun::bot::types::OptionKind Option types 3-11 (1 and 2 are sub-commands and groups).
bindings::zaun::bot::types::OptionValue interactions
voice::PlayerStatus
bindings::zaun::bot::types::Response Callback types 4-9 (8, the autocomplete result, is the return value of on-autocomplete).
bindings::zaun::bot::types::RowItem
bindings::zaun::bot::types::SectionAccessory
Select Builds a select menu: string options or members, roles, mentionables or channels.
bindings::zaun::bot::types::SeparatorSpacing
bindings::zaun::bot::voice::Source Where a track’s audio comes from.
presence::Status invisible looks offline to everyone.
bindings::zaun::bot::types::TextInputStyle modals
voice::VoiceEvent What happened, for on-voice-event.
Item Summary
bindings::zaun::bot::community::add_role member.roles.update.
bindings::zaun::bot::timers::after Fires once after ms.
bindings::zaun::bot::audio::buffered_ms The audio written and not yet played, in ms (0 without a stream).
bindings::zaun::bot::timers::cancel
bindings::zaun::bot::audio::clear Drops everything buffered at once, keeping the stream open (to interrupt speech).
bindings::zaun::bot::voice::clear_queue Empties the queue; the current track keeps playing.
presence::clear_status Clears the custom status.
bindings::zaun::bot::dms::close dm.close: hides it from the bot’s list.
bindings::zaun::bot::audio::close Closes the stream: once the buffer has played (drain), or at once. The player resumes. Nothing happens without a stream.
bindings::zaun::bot::messages::delete message.delete.
bindings::zaun::bot::storage::delete
bindings::zaun::bot::interactions::delete_original Deletes the original response.
dispatch Calls the Bot handler for event.
bindings::zaun::bot::messages::dm A direct message to member member-id (capability dms): opens the DM when needed, then sends. Returns the DM’s channel id and the message id.
bindings::zaun::bot::messages::edit message.edit of one of the bot’s messages.
bindings::zaun::bot::interactions::edit_original Edits the original response (ends a deferred “thinking” state).
bindings::zaun::bot::voice::end_stream The pushed track ends once its buffered packets have played.
bindings::zaun::bot::voice::enqueue Adds track to the queue (≤ 100); returns the queue’s length.
bindings::zaun::bot::timers::every Fires every ms (≥ 1000).
bindings::zaun::bot::http::fetch
bindings::zaun::bot::interactions::followup A follow-up message, within 15 minutes; at most 10.
bindings::zaun::bot::storage::get
bindings::zaun::bot::community::get_channel
bindings::zaun::bot::community::get_member Needs capability members for members the bot has not seen.
bindings::zaun::bot::community::get_role
bindings::zaun::bot::messages::history message.history: up to limit (1-100) messages before before.
mention::is_id Whether id is a well-formed Zaun id: 16 bytes in unpadded base64url (22 characters, the last one of A, Q, g, w).
bindings::zaun::bot::voice::join Joins voice channel channel (leaving another one first). Returns once media can flow (at most about 10 s). FORBIDDEN without voice, CONNECT or SPEAK.
bindings::zaun::bot::community::kick member.kick.
bindings::zaun::bot::voice::leave Leaves; playback stops and the queue is cleared.
bindings::zaun::bot::community::list_channels
bindings::zaun::bot::storage::list_keys Keys starting with prefix, in order, after after, at most limit (≤ 1000).
bindings::zaun::bot::community::list_members
bindings::zaun::bot::dms::list_open dm.list: the DMs the bot has open.
bindings::zaun::bot::community::list_roles
mention::member The text that shows a member mention: <@id> (discord.js userMention).
bindings::zaun::bot::voice::move_ Moves the queued track at from to to (both 0-based); the tracks between shift. NOT_FOUND past the end.
mention::none No mentions.
bindings::zaun::bot::dms::open dm.open: the DM with member-id, created when there is none.
bindings::zaun::bot::audio::open Opens the stream in the bot’s voice channel, pausing the player. CONFLICT when the bot is in no voice channel or a stream is open; UNSUPPORTED for a format the host cannot take
mention::parse The mentions content shows: <@id> (and Discord’s <@!id>) for members, <@&id> for roles, @everyone. Each id once, in order, at most MAX_MEMBERS members and MAX_ROLES r
bindings::zaun::bot::voice::pause
bindings::zaun::bot::voice::play Plays track now, replacing the current one; the queue stays.
bindings::zaun::bot::voice::push Opus packets (2.5 to 120 ms each, ≤ 1000 bytes) for the current pushed track. Returns the audio buffered, in ms; BUSY past 3 s, so push about as fast as it plays.
bindings::zaun::bot::messages::react reaction.add.
bindings::zaun::bot::voice::remove Removes the queued track at index (0 plays next); returns its title. NOT_FOUND past the end.
bindings::zaun::bot::community::remove_role
bindings::zaun::bot::interactions::respond The initial response, within 3 s (the runtime defers automatically at 2.5 s). Returns the message id when the response created a channel message.
bindings::zaun::bot::voice::resume
mention::role The text that shows a role mention: <@&id> (discord.js roleMention).
bindings::zaun::bot::voice::seek Jumps to ms into the current track (past the end: the track ends). UNSUPPORTED for live streams and pushed audio, and on hosts that cannot seek; CONFLICT when nothing plays.
bindings::zaun::bot::messages::send message.send. Returns the new message id.
presence::set Sets the bot’s status and activity (None: no activity).
bindings::zaun::bot::commands::set
bindings::zaun::bot::storage::set QUOTA_EXCEEDED when the grant is used up.
bindings::zaun::bot::presence::set Sets the bot’s status and activity (signal.presence). The host shows changes at most every 3 s: a later call within that time replaces an earlier one that has not gone out. The b
bindings::zaun::bot::voice::set_loop Sets what happens when a track ends (off when the bot joins).
presence::set_status Sets the custom status text and emoji, cleared by the host at expires_at (ms) if given.
presence::set_status_text Sets the custom status text, kept until changed.
bindings::zaun::bot::presence::set_status_text Sets the custom status text and emoji (member.status.set), kept until expires-at (or changed); none for both clears it.
bindings::zaun::bot::voice::set_volume Sets the playback volume, 0-200 % (100 when the bot joins; BAD_REQUEST above 200). Changing it means decoding and re-encoding the Opus audio, so hosts without an Opus encoder ans
bindings::zaun::bot::voice::shuffle Puts the queue in a random order (the current track keeps playing).
bindings::zaun::bot::voice::skip Ends the current track; the next one starts.
bindings::zaun::bot::voice::state Where the bot is and what it plays.
bindings::zaun::bot::voice::stop Ends the current track and clears the queue.
text_choice A text Choice (autocomplete results and fixed choices).
bindings::zaun::bot::community::timeout member.timeout; none clears.
bindings::zaun::bot::messages::unreact reaction.remove of the bot’s own reaction.
bindings::zaun::bot::messages::upload Uploads a file for the bot’s next message (capability attachments). Returns the attachment id to put in message-body.attachments.
bindings::zaun::bot::log::write
bindings::zaun::bot::audio::write_opus Opus packets, for an opus stream. Returns the audio buffered, in ms; BUSY past 3 s.
bindings::zaun::bot::audio::write_pcm Interleaved samples, for a pcm stream; any count (the host frames them). Returns the audio buffered, in ms; BUSY past 3 s.
Item Summary
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).
Item Summary
bindings::zaun::bot::types::ActionRow Type 1: up to 5 buttons, or one select.
ActionRow Builds a types::ActionRow: up to 5 buttons, or one select.
presence::Activity What the bot is doing: build one with Activity::playing, Activity::listening, …
bindings::zaun::bot::types::Activity What a member (or the bot) is doing.
prelude::ApplicationCommand
bindings::zaun::bot::types::Attachment
Audio The bot’s audio output stream.
bindings::zaun::bot::types::Button Type 2.
Button Builds a types::Button.
prelude::Channel
bindings::zaun::bot::types::Checkbox Type 23.
bindings::zaun::bot::types::CheckboxGroup Type 22: 1-10 options.
prelude::Choice
bindings::zaun::bot::types::ChoiceOption
prelude::CommandData
bindings::zaun::bot::types::CommandOption
CommandOptionBuilder Builds a CommandOption.
bindings::zaun::bot::types::CommunityProfile
prelude::ComponentData
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 a
bindings::zaun::bot::types::Container Type 17.
Container Builds a Components V2 types::Container.
Context The interaction being handled, without its data (handlers get the data separately).
bindings::zaun::bot::types::DefaultValue
bindings::zaun::bot::types::Embed
bindings::zaun::bot::types::EmbedAuthor embeds
EmbedBuilder Builds an Embed. Pictures are attachment ids of the same message.
bindings::zaun::bot::types::EmbedField
bindings::zaun::bot::types::EmbedFooter
bindings::zaun::bot::types::EntitySelect
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.
bindings::zaun::bot::types::File Type 13.
bindings::zaun::bot::types::FileUpload Type 19.
prelude::HostError What the host refused, mirroring the protocol’s error codes.
bindings::zaun::bot::types::Interaction
bindings::zaun::bot::types::InteractionMetadata
bindings::zaun::bot::types::Label Type 18.
bindings::zaun::bot::types::Localized
bindings::zaun::bot::types::MediaGallery Type 12: 1-10 items.
bindings::zaun::bot::types::MediaItem
prelude::Member community objects
bindings::zaun::bot::types::MemberRoles
bindings::zaun::bot::types::MemberTimeout until is none when the timeout was cleared.
prelude::Mentions
prelude::Message
bindings::zaun::bot::types::MessageBody What a bot sends: message.send, responses, follow-ups and edits.
bindings::zaun::bot::types::MessageDeleted
bindings::zaun::bot::types::MessageEvent A message, and whether it is in a direct-message channel with the bot.
bindings::zaun::bot::types::MessageFlags messages Discord’s values: 4, 64, 4096, 32768. LOADING is host-set only.
bindings::zaun::bot::types::MessagesDeleted
bindings::zaun::bot::types::Modal
Modal Builds a types::Modal: 1–5 labelled inputs and text blocks.
prelude::ModalData
bindings::zaun::bot::types::ModalValue
audio::PcmFormat PCM the host encodes to Opus.
bindings::zaun::bot::types::Presence status: online, idle, dnd or offline (invisible members look offline).
bindings::zaun::bot::types::RadioGroup Type 21: 2-10 options.
bindings::zaun::bot::types::RawEvent
prelude::Reaction
prelude::Ready events The bot’s own identity, once its connection is up.
bindings::zaun::bot::types::ReceivedOption One option the invoker filled in, with the sub-command path flattened onto the data.
bindings::zaun::bot::types::RegisteredCommand
bindings::zaun::bot::types::Registration What init returns.
Reply Builds a MessageBody. Reply::from("text") is the common case.
bindings::zaun::bot::http::Request
bindings::zaun::bot::types::Resolved
bindings::zaun::bot::http::Response
prelude::Role
bindings::zaun::bot::types::Section Type 9: 1-3 text displays and an accessory.
Section A Components V2 section: 1–3 text blocks with a button beside them.
bindings::zaun::bot::types::SelectOption
bindings::zaun::bot::types::Separator Type 14.
SlashCommand Builds an ApplicationCommand: a slash command, or a user or message context command.
audio::StreamOptions
bindings::zaun::bot::types::StringSelect Type 3.
bindings::zaun::bot::types::SubCommand Type 1.
SubCommand Builds a sub-command.
bindings::zaun::bot::types::SubCommandGroup Type 2.
SubCommandGroup Builds a group of sub-commands (/name group sub).
bindings::zaun::bot::types::TextDisplay Type 10.
TextDisplay A Components V2 text block (markdown, ≤ 4 000 per message in all).
bindings::zaun::bot::types::TextInput Type 4.
TextInput Builds a types::TextInput for a modal.
bindings::zaun::bot::types::Thumbnail Type 11: an image attachment of the same message.
bindings::zaun::bot::voice::Track Something to play.
bindings::zaun::bot::types::Typing
Voice The bot’s voice: one stay at a time.
voice::VoiceState
Item Summary
Bot A Zaun bot. Every handler has a no-op default; implement the ones you need.
bindings::Guest
Options Reads option and modal values by name.
Item Summary
bindings::zaun::bot::presence::Activity
bindings::zaun::bot::commands::ApplicationCommand
bindings::zaun::bot::dms::Channel
bindings::zaun::bot::community::Channel
bindings::Choice
bindings::Event
bindings::zaun::bot::messages::HostError
bindings::zaun::bot::interactions::HostError
bindings::zaun::bot::commands::HostError
bindings::zaun::bot::dms::HostError
bindings::zaun::bot::community::HostError
bindings::zaun::bot::storage::HostError
bindings::zaun::bot::timers::HostError
bindings::zaun::bot::voice::HostError
bindings::zaun::bot::audio::HostError
bindings::zaun::bot::presence::HostError
bindings::zaun::bot::types::Id A Zaun id: base64url without padding (22 characters for 16-byte ids).
bindings::zaun::bot::messages::Id
bindings::zaun::bot::interactions::Id
bindings::zaun::bot::dms::Id
bindings::zaun::bot::community::Id
bindings::zaun::bot::voice::Id
bindings::Interaction
bindings::zaun::bot::community::Member
bindings::zaun::bot::messages::Message
bindings::zaun::bot::messages::MessageBody
bindings::zaun::bot::interactions::MessageBody
bindings::zaun::bot::types::Permissions A permission bitfield (permissions.md the protocol).
bindings::zaun::bot::commands::RegisteredCommand
bindings::Registration
bindings::zaun::bot::interactions::Response
bindings::zaun::bot::community::Role
bindings::zaun::bot::types::Timestamp Milliseconds since the Unix epoch.
bindings::zaun::bot::community::Timestamp
bindings::zaun::bot::presence::Timestamp
bindings::VoiceEvent