Defined in: sdk/js/src/bot.ts:45
One Zaun bot.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Bot():
Bot
Returns
Section titled “Returns”Bot
Properties
Section titled “Properties”
readonlyaudio: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()
Section titled “bufferedMs()”bufferedMs():
number
The audio written and not yet played, in ms (0 without a stream).
Returns
Section titled “Returns”number
clear()
Section titled “clear()”clear():
void
Drops everything buffered at once; the stream stays open.
Returns
Section titled “Returns”void
close()
Section titled “close()”close(
drain?):void
Closes the stream, after the buffer has played (drain, the default) or at once.
Parameters
Section titled “Parameters”drain?
Section titled “drain?”boolean = true
Returns
Section titled “Returns”void
open()
Section titled “open()”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).
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”void
writeOpus()
Section titled “writeOpus()”writeOpus(
packets):number
Opus packets (2.5–120 ms each, ≤ 1000 bytes); returns the ms buffered (BUSY past 3 s).
Parameters
Section titled “Parameters”packets
Section titled “packets”Uint8Array<ArrayBufferLike>[]
Returns
Section titled “Returns”number
writePcm()
Section titled “writePcm()”writePcm(
samples):number
Interleaved samples, any count; returns the ms buffered (BUSY past 3 s).
Parameters
Section titled “Parameters”samples
Section titled “samples”Int16Array
Returns
Section titled “Returns”number
commands
Section titled “commands”
readonlycommands:Map<string,Command>
Defined in: sdk/js/src/bot.ts:64
Commands by name.
community
Section titled “community”
readonlycommunity:object=api.community
Defined in: sdk/js/src/bot.ts:52
addRole
Section titled “addRole”addRole: (
memberId,roleId) =>void
Parameters
Section titled “Parameters”memberId
Section titled “memberId”string
roleId
Section titled “roleId”string
Returns
Section titled “Returns”void
getChannel
Section titled “getChannel”getChannel: (
id) =>Channel
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Channel
getMember
Section titled “getMember”getMember: (
id) =>Member
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”getRole
Section titled “getRole”getRole: (
id) =>Role
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Role
kick: (
memberId,reason?) =>void
Parameters
Section titled “Parameters”memberId
Section titled “memberId”string
reason?
Section titled “reason?”string
Returns
Section titled “Returns”void
listChannels
Section titled “listChannels”listChannels: () =>
Channel[]
Returns
Section titled “Returns”Channel[]
listMembers
Section titled “listMembers”listMembers: (
options) =>Member[]
Parameters
Section titled “Parameters”options?
Section titled “options?”after?
Section titled “after?”string
limit?
Section titled “limit?”number
Returns
Section titled “Returns”Member[]
listRoles
Section titled “listRoles”listRoles: () =>
Role[]
Returns
Section titled “Returns”Role[]
removeRole
Section titled “removeRole”removeRole: (
memberId,roleId) =>void
Parameters
Section titled “Parameters”memberId
Section titled “memberId”string
roleId
Section titled “roleId”string
Returns
Section titled “Returns”void
timeout
Section titled “timeout”timeout: (
memberId,until,reason?) =>void
Times a member out until until (ms); null clears it.
Parameters
Section titled “Parameters”memberId
Section titled “memberId”string
number
reason?
Section titled “reason?”string
Returns
Section titled “Returns”void
config
Section titled “config”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).
readonlydms:object
Defined in: sdk/js/src/bot.ts:54
Direct messages (capability dms).
close()
Section titled “close()”close(
channelId):void
Hides a DM from the bot’s list.
Parameters
Section titled “Parameters”channelId
Section titled “channelId”string
Returns
Section titled “Returns”void
listOpen()
Section titled “listOpen()”listOpen():
Channel[]
The DMs the bot has open.
Returns
Section titled “Returns”Channel[]
open()
Section titled “open()”open(
memberId):Channel
The DM with memberId, opened when there is none.
Parameters
Section titled “Parameters”memberId
Section titled “memberId”string
Returns
Section titled “Returns”Channel
readonlyhttp:object=api.http
Defined in: sdk/js/src/bot.ts:50
fetch()
Section titled “fetch()”fetch(
url,init?):HttpResponse
Parameters
Section titled “Parameters”string
string | Uint8Array<ArrayBufferLike>
headers?
Section titled “headers?”Record<string, string>
method?
Section titled “method?”string
timeoutMs?
Section titled “timeoutMs?”number
Returns
Section titled “Returns”
readonlylog: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.
messages
Section titled “messages”
readonlymessages:object=api.messages
Defined in: sdk/js/src/bot.ts:47
Host APIs (also importable on their own).
delete()
Section titled “delete()”delete(
channelId,messageId):void
Parameters
Section titled “Parameters”channelId
Section titled “channelId”string
messageId
Section titled “messageId”string
Returns
Section titled “Returns”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.
Parameters
Section titled “Parameters”memberId
Section titled “memberId”string
payload
Section titled “payload”Returns
Section titled “Returns”object
channelId
Section titled “channelId”channelId:
string
messageId
Section titled “messageId”messageId:
string
edit()
Section titled “edit()”edit(
channelId,messageId,payload):void
Edits one of the bot’s messages.
Parameters
Section titled “Parameters”channelId
Section titled “channelId”string
messageId
Section titled “messageId”string
payload
Section titled “payload”Returns
Section titled “Returns”void
history()
Section titled “history()”history(
channelId,options?):Message[]
Up to limit (1–100) messages before the sequence before.
Parameters
Section titled “Parameters”channelId
Section titled “channelId”string
options?
Section titled “options?”before?
Section titled “before?”number
limit?
Section titled “limit?”number
Returns
Section titled “Returns”Message[]
react()
Section titled “react()”react(
channelId,messageId,emoji):void
Parameters
Section titled “Parameters”channelId
Section titled “channelId”string
messageId
Section titled “messageId”string
string
Returns
Section titled “Returns”void
send()
Section titled “send()”send(
channelId,payload,options?):string
Posts a message; returns its id.
Parameters
Section titled “Parameters”channelId
Section titled “channelId”string
payload
Section titled “payload”options?
Section titled “options?”replyTo?
Section titled “replyTo?”string
Returns
Section titled “Returns”string
unreact()
Section titled “unreact()”unreact(
channelId,messageId,emoji):void
Parameters
Section titled “Parameters”channelId
Section titled “channelId”string
messageId
Section titled “messageId”string
string
Returns
Section titled “Returns”void
upload()
Section titled “upload()”upload(
channelId,name,mime,bytes):string
Uploads a file for the bot’s next message (capability attachments); returns its id.
Parameters
Section titled “Parameters”channelId
Section titled “channelId”string
string
string
Uint8Array
Returns
Section titled “Returns”string
presence
Section titled “presence”
readonlypresence:object
Defined in: sdk/js/src/bot.ts:60
The bot’s status, activity and custom status text.
clearStatus()
Section titled “clearStatus()”clearStatus():
void
Clears the custom status text and emoji.
Returns
Section titled “Returns”void
set(
status,activity?):void
Sets the status and activity (none: no activity).
Parameters
Section titled “Parameters”status
Section titled “status”activity?
Section titled “activity?”Returns
Section titled “Returns”void
setStatus()
Section titled “setStatus()”setStatus(
text?,emoji?,expiresAt?):void
Sets the custom status text and emoji, cleared by the host at expiresAt (ms) if given.
Parameters
Section titled “Parameters”string
emoji?
Section titled “emoji?”string
expiresAt?
Section titled “expiresAt?”number | bigint
Returns
Section titled “Returns”void
setStatusText()
Section titled “setStatusText()”setStatusText(
text):void
Sets the custom status text, kept until changed.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”void
storage
Section titled “storage”
readonlystorage:object=api.storage
Defined in: sdk/js/src/bot.ts:48
delete()
Section titled “delete()”delete(
key):void
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”void
get(
key):Uint8Array<ArrayBufferLike>
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Uint8Array<ArrayBufferLike>
getJSON()
Section titled “getJSON()”getJSON<
T>(key):T
A JSON value (bigints are not supported by JSON).
Type Parameters
Section titled “Type Parameters”T = unknown
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”T
getString()
Section titled “getString()”getString(
key):string
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”string
keys()
Section titled “keys()”keys(
prefix?,options?):string[]
Keys starting with prefix, in order.
Parameters
Section titled “Parameters”prefix?
Section titled “prefix?”string = ''
options?
Section titled “options?”after?
Section titled “after?”string
limit?
Section titled “limit?”number
Returns
Section titled “Returns”string[]
set(
key,value):void
Parameters
Section titled “Parameters”string
Uint8Array
Returns
Section titled “Returns”void
setJSON()
Section titled “setJSON()”setJSON(
key,value):void
Parameters
Section titled “Parameters”string
unknown
Returns
Section titled “Returns”void
setString()
Section titled “setString()”setString(
key,value):void
Parameters
Section titled “Parameters”string
string
Returns
Section titled “Returns”void
timers
Section titled “timers”
readonlytimers:object=api.timers
Defined in: sdk/js/src/bot.ts:49
after()
Section titled “after()”after(
ms,tag):number
Once after ms; returns the timer id.
Parameters
Section titled “Parameters”number
string
Returns
Section titled “Returns”number
cancel()
Section titled “cancel()”cancel(
id):void
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”void
every()
Section titled “every()”every(
ms,tag):number
Every ms (≥ 1000).
Parameters
Section titled “Parameters”number
string
Returns
Section titled “Returns”number
readonlyvoice:object
Defined in: sdk/js/src/bot.ts:56
Voice channels and music (capability voice).
clearQueue()
Section titled “clearQueue()”clearQueue():
void
Empties the queue; unlike stop, the current track keeps playing.
Returns
Section titled “Returns”void
endStream()
Section titled “endStream()”endStream():
void
The pushed track ends once its buffer has played.
Returns
Section titled “Returns”void
enqueue()
Section titled “enqueue()”enqueue(
t):number
Adds to the queue (≤ 100); returns its length.
Parameters
Section titled “Parameters”string | TrackOptions
Returns
Section titled “Returns”number
join()
Section titled “join()”join(
channelId):void
Joins a voice channel (leaving another first); returns once audio can flow.
Parameters
Section titled “Parameters”channelId
Section titled “channelId”string
Returns
Section titled “Returns”void
leave()
Section titled “leave()”leave():
void
Leaves; playback stops and the queue clears.
Returns
Section titled “Returns”void
moveTrack()
Section titled “moveTrack()”moveTrack(
from,to):void
Moves the queued track at from to to (both 0-based); the tracks between shift.
Parameters
Section titled “Parameters”number
number
Returns
Section titled “Returns”void
pause()
Section titled “pause()”pause():
void
Returns
Section titled “Returns”void
play()
Section titled “play()”play(
t):void
Plays now, replacing the current track (a string is a URL).
Parameters
Section titled “Parameters”string | TrackOptions
Returns
Section titled “Returns”void
push()
Section titled “push()”push(
packets):number
Opus packets for the current pushed track; returns ms buffered (BUSY past 3 s).
Parameters
Section titled “Parameters”packets
Section titled “packets”Uint8Array<ArrayBufferLike>[]
Returns
Section titled “Returns”number
remove()
Section titled “remove()”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.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”string
resume()
Section titled “resume()”resume():
void
Returns
Section titled “Returns”void
seek()
Section titled “seek()”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.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”void
setLoop()
Section titled “setLoop()”setLoop(
mode):void
Sets what happens when a track ends.
Parameters
Section titled “Parameters”LoopMode
Returns
Section titled “Returns”void
setVolume()
Section titled “setVolume()”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.
Parameters
Section titled “Parameters”percent
Section titled “percent”number
Returns
Section titled “Returns”void
shuffle()
Section titled “shuffle()”shuffle():
void
Puts the queue in a random order; the current track keeps playing.
Returns
Section titled “Returns”void
skip()
Section titled “skip()”skip():
void
Returns
Section titled “Returns”void
state()
Section titled “state()”state():
VoiceState
Returns
Section titled “Returns”stop()
Section titled “stop()”stop():
void
Ends the current track and clears the queue.
Returns
Section titled “Returns”void
Methods
Section titled “Methods”command()
Section titled “command()”Call Signature
Section titled “Call Signature”command(
data,execute?,autocomplete?):this
Defined in: sdk/js/src/bot.ts:76
Registers a command; execute answers it (or handle it in interactionCreate).
Parameters
Section titled “Parameters”execute?
Section titled “execute?”(i) => unknown
autocomplete?
Section titled “autocomplete?”(i) => unknown
Returns
Section titled “Returns”this
Call Signature
Section titled “Call Signature”command(
command):this
Defined in: sdk/js/src/bot.ts:77
Registers a command; execute answers it (or handle it in interactionCreate).
Parameters
Section titled “Parameters”command
Section titled “command”Returns
Section titled “Returns”this
component()
Section titled “component()”component(
match,handler):this
Defined in: sdk/js/src/bot.ts:85
Handles clicks and choices whose custom id matches.
Parameters
Section titled “Parameters”Match
handler
Section titled “handler”(i) => unknown
Returns
Section titled “Returns”this
emit()
Section titled “emit()”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.
Type Parameters
Section titled “Type Parameters”K extends keyof BotEvents
Parameters
Section titled “Parameters”K
…Parameters<BotEvents[K]>
Returns
Section titled “Returns”void
exports()
Section titled “exports()”exports():
object
Defined in: sdk/js/src/bot.ts:160
The zaun:bot/bot world’s exports; export them from your entry module.
Returns
Section titled “Returns”object
init: (
config) =>Registration
Parameters
Section titled “Parameters”config
Section titled “config”[string, string][]
Returns
Section titled “Returns”Registration
onAutocomplete
Section titled “onAutocomplete”onAutocomplete: (
interaction) =>Choice[]
Parameters
Section titled “Parameters”interaction
Section titled “interaction”Interaction
Returns
Section titled “Returns”Choice[]
onConfigChange
Section titled “onConfigChange”onConfigChange: (
config) =>void
Parameters
Section titled “Parameters”config
Section titled “config”[string, string][]
Returns
Section titled “Returns”void
onEvent
Section titled “onEvent”onEvent: (
event) =>void
Parameters
Section titled “Parameters”Event
Returns
Section titled “Returns”void
onInteraction
Section titled “onInteraction”onInteraction: (
interaction) =>void
Parameters
Section titled “Parameters”interaction
Section titled “interaction”Interaction
Returns
Section titled “Returns”void
onTimer
Section titled “onTimer”onTimer: (
id,tag) =>void
Parameters
Section titled “Parameters”bigint
string
Returns
Section titled “Returns”void
onVoiceEvent
Section titled “onVoiceEvent”onVoiceEvent: (
event) =>void
Parameters
Section titled “Parameters”VoiceEvent
Returns
Section titled “Returns”void
modal()
Section titled “modal()”modal(
match,handler):this
Defined in: sdk/js/src/bot.ts:91
Handles submitted modals whose custom id matches.
Parameters
Section titled “Parameters”Match
handler
Section titled “handler”(i) => unknown
Returns
Section titled “Returns”this
off<
K>(event,listener):this
Defined in: sdk/js/src/bot.ts:103
Type Parameters
Section titled “Type Parameters”K extends keyof BotEvents
Parameters
Section titled “Parameters”K
listener
Section titled “listener”BotEvents[K]
Returns
Section titled “Returns”this
on<
K>(event,listener):this
Defined in: sdk/js/src/bot.ts:96
Type Parameters
Section titled “Type Parameters”K extends keyof BotEvents
Parameters
Section titled “Parameters”K
listener
Section titled “listener”BotEvents[K]
Returns
Section titled “Returns”this