Skip to content

Defined in: sdk/js/src/bot.ts:45

One Zaun bot.

new Bot(): Bot

Bot

readonly audio: object

Defined in: sdk/js/src/bot.ts:58

Low-level audio output in the bot’s voice channel: write Opus or PCM yourself.

bufferedMs(): number

The audio written and not yet played, in ms (0 without a stream).

number

clear(): void

Drops everything buffered at once; the stream stays open.

void

close(drain?): void

Closes the stream, after the buffer has played (drain, the default) or at once.

boolean = true

void

open(options): void

Opens the stream, 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 (PCM without an encoder).

AudioStreamOptions

void

writeOpus(packets): number

Opus packets (2.5–120 ms each, ≤ 1000 bytes); returns the ms buffered (BUSY past 3 s).

Uint8Array<ArrayBufferLike>[]

number

writePcm(samples): number

Interleaved samples, any count; returns the ms buffered (BUSY past 3 s).

Int16Array

number


readonly commands: Map<string, Command>

Defined in: sdk/js/src/bot.ts:64

Commands by name.


readonly community: object = api.community

Defined in: sdk/js/src/bot.ts:52

addRole: (memberId, roleId) => void

string

string

void

getChannel: (id) => Channel

string

Channel

getMember: (id) => Member

string

Member

getRole: (id) => Role

string

Role

kick: (memberId, reason?) => void

string

string

void

listChannels: () => Channel[]

Channel[]

listMembers: (options) => Member[]

string

number

Member[]

listRoles: () => Role[]

Role[]

removeRole: (memberId, roleId) => void

string

string

void

timeout: (memberId, until, reason?) => void

Times a member out until until (ms); null clears it.

string

number

string

void


config: ReadonlyMap<string, string>

Defined in: sdk/js/src/bot.ts:69

The bot’s configuration: the keys its manifest declares in [config], with the owner’s values or the defaults. Set at init, replaced on every change (config event).


readonly dms: object

Defined in: sdk/js/src/bot.ts:54

Direct messages (capability dms).

close(channelId): void

Hides a DM from the bot’s list.

string

void

listOpen(): Channel[]

The DMs the bot has open.

Channel[]

open(memberId): Channel

The DM with memberId, opened when there is none.

string

Channel


readonly http: object = api.http

Defined in: sdk/js/src/bot.ts:50

fetch(url, init?): HttpResponse

string

string | Uint8Array<ArrayBufferLike>

Record<string, string>

string

number

HttpResponse


readonly log: Record<"trace" | "debug" | "info" | "warn" | "error", (…args) => void> = api.log

Defined in: sdk/js/src/bot.ts:51


me: Me

Defined in: sdk/js/src/bot.ts:62

Who the bot is, once the host’s ready event arrived.


readonly messages: object = api.messages

Defined in: sdk/js/src/bot.ts:47

Host APIs (also importable on their own).

delete(channelId, messageId): void

string

string

void

dm(memberId, payload): object

A direct message to memberId (capability dms): opens the DM when needed. Returns the DM’s channel id and the message id.

string

MessagePayload

object

channelId: string

messageId: string

edit(channelId, messageId, payload): void

Edits one of the bot’s messages.

string

string

MessagePayload

void

history(channelId, options?): Message[]

Up to limit (1–100) messages before the sequence before.

string

number

number

Message[]

react(channelId, messageId, emoji): void

string

string

string

void

send(channelId, payload, options?): string

Posts a message; returns its id.

string

MessagePayload

string

string

unreact(channelId, messageId, emoji): void

string

string

string

void

upload(channelId, name, mime, bytes): string

Uploads a file for the bot’s next message (capability attachments); returns its id.

string

string

string

Uint8Array

string


readonly presence: object

Defined in: sdk/js/src/bot.ts:60

The bot’s status, activity and custom status text.

clearStatus(): void

Clears the custom status text and emoji.

void

set(status, activity?): void

Sets the status and activity (none: no activity).

PresenceStatus

Activity

void

setStatus(text?, emoji?, expiresAt?): void

Sets the custom status text and emoji, cleared by the host at expiresAt (ms) if given.

string

string

number | bigint

void

setStatusText(text): void

Sets the custom status text, kept until changed.

string

void


readonly storage: object = api.storage

Defined in: sdk/js/src/bot.ts:48

delete(key): void

string

void

get(key): Uint8Array<ArrayBufferLike>

string

Uint8Array<ArrayBufferLike>

getJSON<T>(key): T

A JSON value (bigints are not supported by JSON).

T = unknown

string

T

getString(key): string

string

string

keys(prefix?, options?): string[]

Keys starting with prefix, in order.

string = ''

string

number

string[]

set(key, value): void

string

Uint8Array

void

setJSON(key, value): void

string

unknown

void

setString(key, value): void

string

string

void


readonly timers: object = api.timers

Defined in: sdk/js/src/bot.ts:49

after(ms, tag): number

Once after ms; returns the timer id.

number

string

number

cancel(id): void

number

void

every(ms, tag): number

Every ms (≥ 1000).

number

string

number


readonly voice: object

Defined in: sdk/js/src/bot.ts:56

Voice channels and music (capability voice).

clearQueue(): void

Empties the queue; unlike stop, the current track keeps playing.

void

endStream(): void

The pushed track ends once its buffer has played.

void

enqueue(t): number

Adds to the queue (≤ 100); returns its length.

string | TrackOptions

number

join(channelId): void

Joins a voice channel (leaving another first); returns once audio can flow.

string

void

leave(): void

Leaves; playback stops and the queue clears.

void

moveTrack(from, to): void

Moves the queued track at from to to (both 0-based); the tracks between shift.

number

number

void

pause(): void

void

play(t): void

Plays now, replacing the current track (a string is a URL).

string | TrackOptions

void

push(packets): number

Opus packets for the current pushed track; returns ms buffered (BUSY past 3 s).

Uint8Array<ArrayBufferLike>[]

number

remove(index): string

Removes the queued track at index (0 plays next); returns its title. Throws NOT_FOUND past the end. Like every queue call, UNSUPPORTED on hosts without queue control.

number

string

resume(): void

void

seek(ms): void

Jumps to ms into the current track; past the end, the track ends. Throws UNSUPPORTED for live streams and pushed audio, and on hosts that cannot seek; CONFLICT when nothing plays.

number

void

setLoop(mode): void

Sets what happens when a track ends.

LoopMode

void

setVolume(percent): void

Sets the playback volume, 0–200 % (100 when the bot joins). Throws ZaunError BAD_REQUEST (detail percent) outside 0–200, checked before the call, and UNSUPPORTED on hosts without an Opus encoder, which is most of them for now: tell the member and go on.

number

void

shuffle(): void

Puts the queue in a random order; the current track keeps playing.

void

skip(): void

void

state(): VoiceState

VoiceState

stop(): void

Ends the current track and clears the queue.

void

command(data, execute?, autocomplete?): this

Defined in: sdk/js/src/bot.ts:76

Registers a command; execute answers it (or handle it in interactionCreate).

CommandLike

(i) => unknown

(i) => unknown

this

command(command): this

Defined in: sdk/js/src/bot.ts:77

Registers a command; execute answers it (or handle it in interactionCreate).

Command

this


component(match, handler): this

Defined in: sdk/js/src/bot.ts:85

Handles clicks and choices whose custom id matches.

Match

(i) => unknown

this


emit<K>(event, …args): void

Defined in: sdk/js/src/bot.ts:110

Calls every listener of event; errors go to error listeners and the log.

K extends keyof BotEvents

K

…Parameters<BotEvents[K]>

void


exports(): object

Defined in: sdk/js/src/bot.ts:160

The zaun:bot/bot world’s exports; export them from your entry module.

object

init: (config) => Registration

[string, string][]

Registration

onAutocomplete: (interaction) => Choice[]

Interaction

Choice[]

onConfigChange: (config) => void

[string, string][]

void

onEvent: (event) => void

Event

void

onInteraction: (interaction) => void

Interaction

void

onTimer: (id, tag) => void

bigint

string

void

onVoiceEvent: (event) => void

VoiceEvent

void


modal(match, handler): this

Defined in: sdk/js/src/bot.ts:91

Handles submitted modals whose custom id matches.

Match

(i) => unknown

this


off<K>(event, listener): this

Defined in: sdk/js/src/bot.ts:103

K extends keyof BotEvents

K

BotEvents[K]

this


on<K>(event, listener): this

Defined in: sdk/js/src/bot.ts:96

K extends keyof BotEvents

K

BotEvents[K]

this