Skip to content

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.

  1. 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 zbot

    Or download zbot for Linux, macOS or Windows from the zaun-bot releases. esbuild and jco (which turn your TypeScript into a component) are installed into the project by npm install, so zbot never downloads anything itself.

  2. Create a bot.

    Terminal window
    zbot new ping --lang ts && cd ping
    npm install
    • Directoryping/
      • package.json depends on @zaun/bot
      • tsconfig.json
      • zaun-bot.toml the manifest: what the bot asks for
      • Directorysrc/
        • index.ts a /ping bot
  3. Write the bot.

    A bot is a Bot object: register commands with bot.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();
  4. 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
  5. Build, pack and inspect.

    Terminal window
    zbot build # esbuild src/index.ts β†’ jco componentize β†’ target/bot.wasm
    zbot pack --unsigned # org.example.ping-0.1.0.zbot
    zbot inspect *.zbot # what it is and what it asks for, in plain words
  6. Install it on a host. For a development package, the host needs allow_unsigned = true in its [bots] configuration.

    Terminal window
    zaun-host bot install --community <COMMUNITY_ID> org.example.ping-0.1.0.zbot

    The command shows what the bot asks for and asks you to confirm. Members now see /ping in their command picker.