Skip to content

Ping (hosted bot)

The smallest bot there is: one slash command, one reply. It asks only for VIEW_CHANNEL and SEND_MESSAGES, with no message content, no network and no storage.

Source in zaun-bot: examples/ts/ping (TypeScript) and examples/rust/ping (Rust).

src/index.ts
// `/ping` → "pong", in TypeScript. Shows "Listening to /ping" as its activity.
import { Activity, Bot, SlashCommandBuilder } from '@zaun/bot';
const bot = new Bot();
bot.on('init', () => bot.presence.set('online', Activity.listening('/ping')));
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();
zaun-bot.toml
app_id = "org.zaun.examples.ts-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.
  • The command is registered every time the bot starts (bot.command(..) in TypeScript, Bot::commands in Rust).
  • When the instance starts, it sets its activity: members see “Listening to /ping” next to it (Status and presence). Setting its own status needs no capability.
  • The handler answers with a reply. A refused reply (for example, the bot lost SEND_MESSAGES in that channel) is logged (TypeScript: the error event and the host log; Rust: log_info!).
Terminal window
git clone https://github.com/zaunchat/zaun-bot && cd zaun-bot/examples/ts/ping
npm install
zbot build && zbot pack --unsigned
zaun-host bot install --community <ID> *.zbot # on a host with allow_unsigned = true