Docs menu

Platform APIs

Discord API

Every handle of the Discord fake: the discord fixture, the people and objects a test creates on it, and what they read and wait for. How to test a Discord app or agent, step by step, is in the Discord guide.

Each call is shown in every SDK's language, with its required options (the table under it lists them all). Arguments go first; options are TypeScript's trailing object, Python's keyword arguments and Rust's builder setters. The variable names are the ones the calls return elsewhere on these pages, so user is a DiscordUser handle.

Besides the errors listed with each method, most methods can fail with action_requires, cross_workspace_credential, fake_actor_in_live_world, internal, invalid_argument, live_misconfigured, live_not_allowlisted, not_found, session_not_found, unauthorized, unsupported_in_live: a bad request, a closed session, or live mode refusing or misconfigured.

DiscordFixture#

Returned by Session.discord().

FieldPython / RustType
appappDiscordApp
apiUrlapi_urlstring
guildguildDiscordGuild
gatewayConnectionsgateway_connectionsnumber

createUser()#

Create a person in the guild.

const user = await discord.createUser({ name: "…" });
ParameterTypeRequired
namestringyesoption
idstringnooption
adminbooleannooption
botbooleannooption
tokenstringnooption; read from CHANNELSTACK_DISCORD_USER_{name}_TOKEN when left out

Returns DiscordUser.

users()#

The people this session created.

const users = await discord.users();

Returns DiscordUsers.

createApp()#

Make another app in the guild, with its own application, bot user, token and Ed25519 key (decision 0027), or return the one made with this name and settings. Its bot connects to the Gateway with its own token; its interactions go to CHANNELSTACK_DISCORD_APP_<NAME>_WEBHOOK_URL, or over its Gateway connection.

const app = await discord.createApp({ name: "…" });
ParameterPython / RustTypeRequired
namenamestringyesoption
privilegedIntentsprivileged_intentsArray<"GUILD_MEMBERS" | "GUILD_PRESENCES" | "MESSAGE_CONTENT">nooption

Returns DiscordApp.

Live: refused with unsupported_in_live: not yet: live, the guild holds only the app channelstack has credentials for.

apps()#

The apps this session used: the built-in one first, then each it got from createApp, in the order it first did. Another session's are not_found here.

const apps = await discord.apps();

Returns DiscordApps.

Live: refused with unsupported_in_live: not yet: live, the guild holds only the app channelstack has credentials for.

createChannel()#

Create a text channel. Only the listed participants see it (a private channel); include the app for the bot to hear it.

const channel = await discord.createChannel({ name: "…" });
ParameterPython / RustTypeRequired
namenamestringnooption
participantsparticipantsArray<DiscordUser | DiscordApp>nooption
readOnlyread_onlybooleannooption
topictopicstringnooption

Returns DiscordChannel.

channels()#

The session's channels, threads and DMs.

const channels = await discord.channels();

Returns DiscordChannels.

verifyEndpoint()#

Discord's check of the app's interactions endpoint, as when it is saved in the developer portal: a PING it must answer with a PONG, and one with a bad signature it must refuse with 401.

const endpointCheck = await discord.verifyEndpoint();

Returns DiscordEndpointCheck.

Live: refused with unsupported_in_live: Discord checks an interactions endpoint when it is saved in the developer portal, which no API does.

deliveries()#

Every Gateway dispatch and interaction channelstack sent the bot for this session, with every attempt.

const deliveries = await discord.deliveries({ type: "…" });
ParameterPython / RustTypeRequired
typetype · r#typestringnooption
resourceresourceDiscordChannelnooption
appappDiscordAppnooption

Returns DiscordDeliveries.

Live: refused with unsupported_in_live: Live, the platform delivers to the agent itself and channelstack isn't in the path (delivery chaos is fake-only).

calls()#

The REST calls the bot made about this session's channels, messages and interactions, by route (POST /channels/{channel.id}/messages). Calls about nothing a session owns (GET /gateway/bot) are in no session.

const apiCalls = await discord.calls({ operation: "…" });
ParameterTypeRequired
operationstringnooption
errortrue | stringnooption

Returns DiscordApiCalls.

Live: needs proxy mode: Discord shows an ephemeral message to its person alone, and no bot API reads it back; proxy mode sees the agent's own calls. Proxy mode doesn't read the app's calls back live yet (#24), so for now the call is refused with action_requires and the test is skipped.

fault()#

Inject a fault: rate-limit the bot's calls of a route (removed when this session closes), or drop its Gateway connection just before the next dispatch.

const fault = await discord.fault({ type });
ParameterPython / RustTypeRequired
typetype · r#type"rate_limit" | "drop_gateway"yesoption
routeroutestringnooption
retryAfterretry_afterDurationnooption
timestimesnumbernooption
appappDiscordAppnooption

Returns DiscordFault.

Live: refused with unsupported_in_live: a fault changes what the bot's calls and its Gateway connection get, and live nothing sits between the bot and Discord: its Gateway doesn't go through the proxy.

waitForCall()#

Waits for the next API call from the agent after the last one this handle returned: it polls calls() and never sleeps longer than it must.

const apiCall = await discord.waitForCall({ operation: "…" });
ParameterTypeRequired
operationstringnofilter
errortrue | stringnofilter
timeoutDurationnodefault 10s

Returns DiscordApiCall. When the time is up, it fails with what it was waiting for.

DiscordApp#

Returned by DiscordFixture.createApp().

FieldPython / RustType
ididstring
namenamestring
kindkind"app"
channelchannel"discord"
botUserIdbot_user_idstring
botTokenbot_tokenstring
publicKeypublic_keystring
guildIdguild_idstring

say()#

An app a test made writes, as its own POST /channels/{id}/messages would: in a channel or thread its bot sees, or in a DM with the person in to. No bot writes to another bot in a DM (50007).

const message = await app.say("…", { channel });
ParameterTypeRequired
textstring | DiscordMessageInputyespositional
channelDiscordChannelnooption
toDiscordUser | DiscordApp | Array<DiscordUser | DiscordApp>nooption

Returns DiscordMessage.

Errors missing_access, empty_message, cannot_message_user, missing_permissions, invalid_form_body.

Live: refused with unsupported_in_live: not yet: live, the guild holds only the app channelstack has credentials for.

reply()#

An app a test made replies to a message: Discord's reply, in the message's channel, which quotes it.

const result = await app.reply("…", { message });
ParameterTypeRequired
textstring | DiscordMessageInputyespositional
messageDiscordMessageyesoption

Returns DiscordMessage.

Errors missing_access, empty_message, missing_permissions, invalid_form_body.

Live: refused with unsupported_in_live: not yet: live, the guild holds only the app channelstack has credentials for.

react()#

An app a test made reacts to a message.

const delivery = await app.react("…", { message });
ParameterTypeRequired
emojistringyespositional
messageDiscordMessageyesoption

Returns DiscordDelivery | undefined.

Errors missing_access, missing_permissions.

Live: refused with unsupported_in_live: not yet: live, the guild holds only the app channelstack has credentials for.

unreact()#

An app a test made takes its reaction back.

const delivery = await app.unreact("…", { message });
ParameterTypeRequired
emojistringyespositional
messageDiscordMessageyesoption

Returns DiscordDelivery | undefined.

Errors missing_access, missing_permissions.

Live: refused with unsupported_in_live: not yet: live, the guild holds only the app channelstack has credentials for.

DiscordUser#

Returned by DiscordFixture.createUser().

FieldPython / RustType
ididstring
namenamestring
kindkind"user"
channelchannel"discord"
usernameusernamestring
isAdminis_adminboolean
isBotis_botboolean

say()#

Write a message in a channel or thread, or in a DM with the person or app in to.

const message = await user.say("…", { channel });
ParameterTypeRequired
textstring | DiscordMessageInputyespositional
channelDiscordChannelnooption
toDiscordUser | DiscordApp | Array<DiscordUser | DiscordApp>nooption

Returns DiscordMessage.

Errors missing_access, empty_message, missing_permissions, invalid_form_body.

reply()#

Reply to a message: Discord's reply, in the message's channel, which quotes it.

const result = await user.reply("…", { message });
ParameterTypeRequired
textstring | DiscordMessageInputyespositional
messageDiscordMessageyesoption

Returns DiscordMessage.

Errors missing_access, empty_message, missing_permissions, invalid_form_body.

edit()#

Edit one of this person's own messages.

const result = await user.edit("…", { message });
ParameterTypeRequired
textstring | DiscordMessageInputyespositional
messageDiscordMessageyesoption

Returns DiscordMessage.

Errors cannot_edit_others_message, empty_message, invalid_form_body.

delete()#

Delete a message: this person's own, or anyone's for an admin.

await user.delete({ message });
ParameterTypeRequired
messageDiscordMessageyesoption

Returns nothing.

Errors missing_permissions.

react()#

React to a message with an emoji.

const delivery = await user.react("…", { message });
ParameterTypeRequired
emojistringyespositional
messageDiscordMessageyesoption

Returns DiscordDelivery | undefined.

Errors missing_permissions.

unreact()#

Take this person's reaction off a message.

const delivery = await user.unreact("…", { message });
ParameterTypeRequired
emojistringyespositional
messageDiscordMessageyesoption

Returns DiscordDelivery | undefined.

Errors missing_permissions.

startThread()#

Start a thread: from a message, or in a channel.

const channel = await user.startThread("…", { message });
ParameterTypeRequired
namestringyespositional
messageDiscordMessagenooption
channelDiscordChannelnooption

Returns DiscordChannel.

Errors missing_permissions, thread_already_created.

openDM()#

Open (or reuse) a DM with the app or another person.

const channel = await user.openDM(participant);
ParameterTypeRequired
participantDiscordUser | DiscordAppyespositional

Returns DiscordChannel.

Live: refused with unsupported_in_live: live, a person is a bot of their own, and Discord lets no bot write to another bot in a DM.

invite()#

Let people or the app see a channel. The person must be an admin.

await user.invite(participants, { channel });
ParameterTypeRequired
participantsDiscordUser | DiscordApp | Array<DiscordUser | DiscordApp>yespositional
channelDiscordChannelyesoption

Returns nothing.

Errors missing_permissions.

runCommand()#

Run one of an app's slash commands in a channel, e.g. /deploy web staging or /deploy service:web: the built-in app's, or app's, as a person picks one app's command when several have it.

const delivery = await user.runCommand("…", { channel });
ParameterTypeRequired
commandstringyespositional
channelDiscordChannelyesoption
appDiscordAppnooption

Returns DiscordDelivery | undefined. While refused with not_found, it tries again until the wait's timeout.

Errors missing_permissions.

Live: refused with unsupported_in_live: live, a person is a bot of their own, and Discord lets no bot run another app's command or press its button.

click()#

Press a button, found by its label or custom_id: on a message, or on the app's newest message in a channel or thread that has it.

const delivery = await user.click("…", { message });
ParameterTypeRequired
buttonstring | DiscordButtonRefyespositional
messageDiscordMessagenooption
channelDiscordChannelnooption

Returns DiscordDelivery | undefined. While refused with not_found, it tries again until the wait's timeout.

Live: refused with unsupported_in_live: live, a person is a bot of their own, and Discord lets no bot run another app's command or press its button.

ephemeral()#

Messages only this person sees: the app's ephemeral responses, and "This interaction failed".

const ephemeralMessages = await user.ephemeral();

Returns DiscordEphemeralMessages. It reads once the app is quiet.

Live: needs proxy mode: Discord shows an ephemeral message to its person alone, and no bot API reads it back; proxy mode sees the agent's own calls. Proxy mode doesn't read the app's calls back live yet (#24), so for now the call is refused with action_requires and the test is skipped.

DiscordMessage#

Returned by DiscordApp.say(), DiscordApp.reply(), DiscordUser.say(), DiscordUser.reply().

FieldPython / RustType
ididstring
channelIdchannel_idstring
channelchannelDiscordChannel
authorauthorDiscordUser | DiscordApp
texttextstring
contentcontentstring
embedsembedsunknown[]
componentscomponentsunknown[]
postedAtposted_atstring
editededitedboolean
replyToreply_tostring | undefined
threadthreadDiscordChannel | undefined
visibleTovisible_toDiscordUser | undefined
deliverydeliveryDiscordDelivery | undefined

refresh()#

Re-read a message: its latest text, edits and thread.

const updated = await message.refresh();

Returns DiscordMessage.

replies()#

What answers a message, oldest first: Discord's replies to it, and the messages of the thread started from it.

const replies = await message.replies();

Returns DiscordReplies.

transcript()#

A message and what answers it, as a person reads them.

const transcript = await message.transcript({ as });
ParameterPython / RustTypeRequired
asas_ · r#asDiscordUser | DiscordAppnooption

Returns DiscordTranscript.

reactions()#

The reactions on a message, and who added each.

const reactions = await message.reactions();

Returns DiscordReactions.

deliveryFor()#

The first Gateway dispatch this message caused to this app's bot (decision 0027), or nothing when it wasn't told.

const delivery = await message.deliveryFor(app);
ParameterTypeRequired
appDiscordAppyespositional

Returns DiscordDelivery | undefined.

Live: refused with unsupported_in_live: Live, the platform delivers to the agent itself and channelstack isn't in the path (delivery chaos is fake-only).

deliveries()#

Every Gateway dispatch this message caused to the apps' bots.

const messageDeliveries = await message.deliveries();

Returns DiscordMessageDeliveries.

Live: refused with unsupported_in_live: Live, the platform delivers to the agent itself and channelstack isn't in the path (delivery chaos is fake-only).

waitForReply()#

Waits for the next reply after the last one this handle returned: it polls replies() and never sleeps longer than it must.

const updated = await message.waitForReply({ from: "my-agent" });
ParameterPython / RustTypeRequired
fromfrom_ · fromDiscordUser | DiscordApp | stringnoa handle, or a name
timeouttimeoutDurationnodefault 10s

Returns DiscordMessage. When the time is up, it fails with what it was waiting for.

latestReply()#

The latest reply, once the app is quiet. Waits for at least one: it polls replies() and never sleeps longer than it must.

const updated = await message.latestReply({ from: "my-agent" });
ParameterPython / RustTypeRequired
fromfrom_ · fromDiscordUser | DiscordApp | stringnoa handle, or a name
timeouttimeoutDurationnodefault 10s
quietForquiet_forDurationnodefault 750ms

Returns DiscordMessage. When the time is up, it fails with what it was waiting for.

DiscordChannel#

Returned by DiscordFixture.createChannel(), DiscordUser.startThread(), DiscordUser.openDM().

FieldPython / RustType
ididstring
kindkind"text" | "dm" | "public_thread"
channelchannel"discord"
namenamestring | undefined
parentIdparent_idstring | undefined
starterIdstarter_idstring | undefined

messages()#

A channel's or thread's messages, oldest first.

const messages = await channel.messages();

Returns DiscordMessages.

members()#

Who sees a channel: a text channel's participants, a DM's two ends; a thread's are its channel's. Admins see every channel without being listed.

const members = await channel.members();

Returns DiscordMembers.

threads()#

The threads in a channel.

const threads = await channel.threads();

Returns DiscordThreads.

transcript()#

A channel or thread as a person reads it, each thread under the message that starts it.

const transcript = await channel.transcript({ as });
ParameterPython / RustTypeRequired
asas_ · r#asDiscordUser | DiscordAppnooption

Returns DiscordTranscript.

waitForMessage()#

Waits for the next message after the last one this handle returned: it polls messages() and never sleeps longer than it must.

const message = await channel.waitForMessage({ from: "my-agent" });
ParameterPython / RustTypeRequired
fromfrom_ · fromDiscordUser | DiscordApp | stringnoa handle, or a name
timeouttimeoutDurationnodefault 10s

Returns DiscordMessage. When the time is up, it fails with what it was waiting for.

DiscordDelivery#

Returned by DiscordApp.react(), DiscordApp.unreact(), DiscordUser.react(), DiscordUser.unreact().

FieldPython / RustType
ididstring
channelchannel"discord"
appappstring
typetype · r#typestring
payloadpayloadunknown | undefined
attemptsattemptsDeliveryAttempt[]
statusstatus"pending" | "acknowledged" | "failed" | "timed_out" | "unreachable"

refresh()#

Re-read a delivery: its attempts and status.

const updated = await delivery.refresh();

Returns DiscordDelivery.

Live: refused with unsupported_in_live: Live, the platform delivers to the agent itself and channelstack isn't in the path (delivery chaos is fake-only).

redeliver()#

Dispatch the same event to the bot again, as a replay after a RESUME would.

const deliveryAttempt = await delivery.redeliver();

Returns DeliveryAttempt.

Live: refused with unsupported_in_live: Discord dispatches an event once a session, and has no API to send one again.

resend()#

Send an interaction again, forged: signed with a key that isn't the app's, which its endpoint must refuse with 401.

const deliveryAttempt = await delivery.resend({ badSignature });
ParameterPython / RustTypeRequired
badSignaturebad_signaturebooleannooption

Returns DeliveryAttempt.

Live: refused with unsupported_in_live: Live, the platform delivers to the agent itself and channelstack isn't in the path (delivery chaos is fake-only).

settled()#

Waits for the delivery to settle: it polls refresh() and never sleeps longer than it must.

const updated = await delivery.settled();
ParameterTypeRequired
timeoutDurationnodefault 10s

Returns DiscordDelivery. When the time is up, it fails with what it was waiting for.

DiscordFault#

Returned by DiscordFixture.fault().

FieldType
idstring

undo()#

Remove a fault.

await fault.undo();

Returns nothing. Disposing the handle calls it.

Live: refused with unsupported_in_live: a fault changes what the bot's calls and its Gateway connection get, and live nothing sits between the bot and Discord: its Gateway doesn't go through the proxy.

Types#

Plain values the handles return and take.

DiscordGuild#

FieldType
idstring
namestring

DiscordApps#

type DiscordApps = DiscordApp[];

DiscordMessageInput#

FieldType
contentstring | undefined
embedsunknown[] | undefined

DiscordUsers#

type DiscordUsers = DiscordUser[];

DiscordChannels#

type DiscordChannels = DiscordChannel[];

DiscordButtonRef#

FieldPython / RustType
labellabelstring | undefined
customIdcustom_idstring | undefined

DiscordEphemeralMessages#

type DiscordEphemeralMessages = DiscordMessage[];

DiscordMessages#

type DiscordMessages = DiscordMessage[];

DiscordMembers#

type DiscordMembers = Array<DiscordUser | DiscordApp>;

DiscordThreads#

type DiscordThreads = DiscordChannel[];

DiscordTranscript#

FieldType
entriesDiscordTranscriptEntry[]
textstring

DiscordTranscriptEntry#

FieldPython / RustType
ididstring
authorauthorDiscordPrincipal
atatstring
texttextstring
controlscontrolsstring[]
editededitedboolean
depthdepthnumber
replyToreply_tostring | undefined
streamingstreaming"open" | undefined
visibleTovisible_toDiscordPrincipal | undefined

DiscordPrincipal#

FieldType
idstring
namestring
kind"user" | "app"

DiscordReplies#

type DiscordReplies = DiscordMessage[];

DiscordReactions#

type DiscordReactions = DiscordReaction[];

DiscordReaction#

FieldType
emojistring
byArray<DiscordUser | DiscordApp>

DiscordMessageDeliveries#

type DiscordMessageDeliveries = DiscordDelivery[];

DiscordEndpointCheck#

FieldType
validboolean
problemsstring[]
deliveriesstring[]

DiscordDeliveries#

type DiscordDeliveries = DiscordDelivery[];

DiscordApiCalls#

type DiscordApiCalls = DiscordApiCall[];

DiscordApiCall#

FieldPython / RustType
ididstring
channelchannel"discord"
operationoperationstring
methodmethodstring
pathpathstring
atatstring
durationMsduration_msnumber
requestrequestunknown | undefined
responseStatusresponse_statusnumber
responseresponseunknown | undefined
errorerrorstring | undefined

This page is generated from the control API's routes by codegen/src/emit/docs.ts: suggest changes there.