Skip to content

Bots answer through the same connection as everything else, so an app uses them with a few calls. This page is about an app using bots; to write one, see Bots (hosted) or External bots.

The client keeps the community’s bot commands and bot cards up to date, and loads them once the community is ready.

client.on("appsReady", (community) => {
for (const command of community.commands.values()) console.log(`/${command.name}`);
for (const card of community.bots.values()) console.log(card.name, card.capabilities);
});
client.on("commandsUpdate", (community, botId) => { /* a bot changed its commands */ });
client.on("botUpdate", (community, card) => { /* installed, updated, re-granted, disabled */ });
const me = community.member(community.data.me);
const usable = [...community.commands.values()].filter((c) => me.canUse(c, channel));

A member’s isBot and botId tell whether it is a bot; community.bot(botId) fetches its card.

Every member can read every bot’s card: its permissions, whether it can read message content, the hosts it may contact, its storage, voice and direct-message capabilities. Show it wherever a bot’s name appears (the BOT badge).

The host passes each use to the bot; the bot’s answer arrives as an event (a normal message, or one of the events below).

// /weather city: Cairo
await channel.invokeCommand(weather, [{ name: "city", type: 3, value: "Cairo" }]);
// A button or select on a bot's message
await message.click("vote:yes");
// Suggestions while typing: they come as `autocomplete`
await channel.autocomplete(weather, [{ name: "city", type: 3, value: "Ca", focused: true }]);
client.on("autocomplete", ({ choices }) => showSuggestions(choices));
// A modal the bot opened
client.on("modalOpen", async ({ channel, interaction, customId, components }) => {
await channel.submitModal(interaction, customId, [{ custom_id: "subject", value: "Hello" }]);
});
// Replies only you see, and failures
client.on("interactionReply", ({ op, message }) => { /* ephemeral: created, updated, deleted */ });
client.on("interactionFail", ({ reason }) => { /* "timeout", "bot_error" or "bot_unavailable" */ });

Using a command needs USE_APPLICATION_COMMANDS (on @everyone by default) and whatever default permissions the command asks for.

Only the community’s owner, or the host’s operator with zaun-host bot, installs bots. Upload the .zbot file as an attachment first, then install it; show the owner what it asks for before they confirm.

const card = await community.installBot(attachmentId); // grants: what the manifest asks, within the host's ceiling
await community.grantBot(card.bot_id, { capabilities: { message_content: false } });
await community.disableBot(card.bot_id);
await community.enableBot(card.bot_id);
await community.updateBot(card.bot_id, newAttachmentId); // wider requests wait for approval
await community.removeBot(card.bot_id);
await community.registerBot(member, "Helper"); // mark a member as an external bot