Bot quick start
A Zaun bot is a WebAssembly component that runs inside the communityβs own host. You can write it
in TypeScript with @zaun/bot or in Rust with the zaun-bot crate: both build to the same
kind of package and use the same host features. This guide shows TypeScript first; pick the Rust
tab to follow along in Rust. TypeScript or Rust? compares them.
-
Install the tools.
You need Node.js 22 or newer with npm, and
zbot:Terminal window cargo install --git https://github.com/zaunchat/zaun-bot zbotOr download
zbotfor Linux, macOS or Windows from the zaun-bot releases. esbuild and jco (which turn your TypeScript into a component) are installed into the project bynpm install, sozbotnever downloads anything itself.Terminal window rustup target add wasm32-wasip2cargo install --git https://github.com/zaunchat/zaun-bot zbotOr download
zbotfor Linux, macOS or Windows from the zaun-bot releases. -
Create a bot.
Terminal window zbot new ping --lang ts && cd pingnpm installDirectoryping/
- package.json depends on @zaun/bot
- tsconfig.json
- zaun-bot.toml the manifest: what the bot asks for
Directorysrc/
- index.ts a /ping bot
Terminal window zbot new ping && cd pingDirectoryping/
- Cargo.toml a cdylib depending on zaun-bot
- zaun-bot.toml the manifest: what the bot asks for
Directorysrc/
- lib.rs a /ping bot
-
Write the bot.
A bot is a
Botobject: register commands withbot.command(builder, handler), then export the functions the host calls, once, at the end of the entry file.src/index.ts import { Bot, SlashCommandBuilder } from '@zaun/bot';const bot = new Bot();bot.command(new SlashCommandBuilder().setName('ping').setDescription('Check that the bot is alive'),(interaction) => {interaction.reply('pong π');},);export const { init, onEvent, onInteraction, onAutocomplete, onTimer, onVoiceEvent } = bot.exports();A bot is a type implementing
Bot, exported once withexport_bot!. Every handler has a no-op default; implement the ones you need.src/lib.rs 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, command: CommandData) {if command.name == "ping" {let _ = ctx.reply("pong π");}}}export_bot!(Ping); -
Say what it needs in the manifest. Ask for the least you can: owners see every request in plain words before they install. The manifest is the same for both languages.
zaun-bot.toml app_id = "org.example.ping"version = "0.1.0"name = "Ping"description = "Answers /ping with pong."permissions = ["VIEW_CHANNEL", "SEND_MESSAGES"][capabilities]# nothing beyond interactions: no message content, no network, no storage -
Build, pack and inspect.
Terminal window zbot build # esbuild src/index.ts β jco componentize β target/bot.wasmzbot pack --unsigned # org.example.ping-0.1.0.zbotzbot inspect *.zbot # what it is and what it asks for, in plain wordsTerminal window zbot build # cargo build --release --target wasm32-wasip2zbot pack --unsigned # org.example.ping-0.1.0.zbotzbot inspect *.zbot # what it is and what it asks for, in plain words -
Install it on a host. For a development package, the host needs
allow_unsigned = truein its[bots]configuration.Terminal window zaun-host bot install --community <COMMUNITY_ID> org.example.ping-0.1.0.zbotThe command shows what the bot asks for and asks you to confirm. Members now see
/pingin their command picker.
- Slash commands and options
- Interactions and responses
- Events, direct messages and voice
- More complete examples