# Discord on boxd

> An instant messaging and VoIP social platform.

- Page: https://boxd.sh/integrations/discord/
- CLI: `run discord` (28 commands, 4 marked common)
- SDK: `import { discord } from "@boxd/run"`; every parameter and response type is at `@boxd/run/discord`
- Triggers: 1
- Connect: `run auth discord` (Sign in with Discord), or https://app.boxd.sh/integrations/detail/discord
- All integrations: https://boxd.sh/integrations/ (Markdown: https://boxd.sh/integrations/index.md)

## From the shell

```sh
run auth discord      # once: prints a link to connect your account
run discord           # list its commands
run discord get-gateway
```

Parameters are flags (`--flag value`); object and array parameters take a JSON string. Output is YAML, or JSON with `--json`. Calls use your own connection; `--scope <name>` uses a connection shared with your team.

## From a script

```ts
import { discord } from "@boxd/run";

const result = await discord.getGateway();
console.log(result);

discord.on("new-message", { channel_id: "…" }, async (event) => {
  // New Discord Message Trigger: runs on this machine, once per event
  console.log(event);
});
```

Run it with `run discord.run.ts`. A script that calls `.on()` keeps running as a job and handles each event.

## Commands

Required flags are listed; `run discord <command> --help` lists the optional ones. "common" marks what `run discord` shows without `--all`.

| Command | SDK method | Required flags | Optional | Description |
|---|---|---|---|---|
| `consume-entitlement` ·deprecated | `discord.consumeEntitlement()` | `--application-id` `--entitlement-id` | 0 | This Discord endpoint requires a bot token and cannot be used by an OAuth2 user connection |
| `delete-test-entitlement` ·deprecated | `discord.deleteTestEntitlement()` | `--application-id` `--entitlement-id` | 0 | This Discord endpoint requires a bot token and cannot be used by an OAuth2 user connection |
| `delete-user-application-role-connection` | `discord.deleteUserApplicationRoleConnection()` | `--application-id` | 0 | Deletes the current user's application role connection for the specified application |
| `edit-application-command-permissions` | `discord.editApplicationCommandPermissions()` | `--application-id` `--command-id` `--guild-id` `--permissions` | 0 | Edits the permissions for a specific application command in a guild |
| `get-application-command-permissions` | `discord.getApplicationCommandPermissions()` | `--application-id` `--command-id` `--guild-id` | 0 | Retrieves the permissions for a specific application command in a guild |
| `get-batch-application-command-permissions` | `discord.getBatchApplicationCommandPermissions()` | `--application-id` `--guild-id` | 0 | Retrieves permissions for all commands of an application in a guild |
| `get-current-user-application-entitlements` | `discord.getCurrentUserApplicationEntitlements()` | `--application-id` | 7 | Retrieves entitlements for the current user and application |
| `get-gateway` ·common | `discord.getGateway()` | — | 0 | Retrieve a valid WebSocket (wss) URL for establishing a Gateway connection to Discord |
| `get-guild-template` | `discord.getGuildTemplate()` | `--code` | 0 | Retrieve information about a Discord guild template using its unique template code |
| `get-guild-widget` | `discord.getGuildWidget()` | `--guild-id` | 0 | Retrieve the guild widget in JSON format |
| `get-guild-widget-png` | `discord.getGuildWidgetPng()` | `--guild-id` | 1 | Retrieve a PNG image widget for a Discord guild |
| `get-invite` ·common ·deprecated | `discord.getInvite()` | `--invite-code` | 3 | Use invite-resolve instead |
| `get-my-guild-member` | `discord.getMyGuildMember()` | `--guild-id` | 0 | Retrieves the guild member object for the currently authenticated user within a specified guild, including roles, nickname, join date, and permissions |
| `get-my-oauth2-authorization` | `discord.getMyOauth2Authorization()` | — | 0 | Retrieves current OAuth2 authorization details for the application, including app info, scopes, token expiration, and user data (contingent on scopes like 'identify') |
| `get-my-user` | `discord.getMyUser()` | — | 0 | Fetches comprehensive profile information for the currently authenticated Discord user, including email if the 'email' scope is granted |
| `get-openid-connect-userinfo` | `discord.getOpenidConnectUserinfo()` | — | 0 | Retrieve OpenID Connect compliant user information for the authenticated user |
| `get-public-keys` | `discord.getPublicKeys()` | — | 0 | Retrieve Discord OAuth2 public keys |
| `get-sku-subscription` | `discord.getSkuSubscription()` | `--sku-id` `--subscription-id` | 0 | Retrieves a specific subscription by ID for a given SKU |
| `get-user` ·common | `discord.getUser()` | `--user-id` | 0 | Retrieve information about a Discord user |
| `get-user-application-role-connection` | `discord.getUserApplicationRoleConnection()` | `--application-id` | 0 | Retrieves the application role connection for the currently authenticated user for a specified application |
| `invite-resolve` ·common | `discord.inviteResolve()` | `--code` | 3 | Resolve and retrieve information about a Discord invite code |
| `leave-guild` ·deprecated | `discord.leaveGuild()` | `--guild-id` | 0 | This endpoint requires a bot token |
| `list-my-connections` | `discord.listMyConnections()` | — | 0 | Retrieves a list of the authenticated user's connected third-party accounts on Discord |
| `list-my-guilds` | `discord.listMyGuilds()` | — | 4 | Lists the current user's guilds, returning partial data for each; primarily used for displaying server lists or verifying memberships |
| `list-sku-subscriptions` | `discord.listSkuSubscriptions()` | `--sku-id` | 4 | Lists all subscriptions for a given SKU |
| `list-sticker-packs` | `discord.listStickerPacks()` | — | 0 | Retrieve all available Discord Nitro sticker packs |
| `modify-current-user` ·deprecated | `discord.modifyCurrentUser()` | — | 3 | This endpoint requires a bot token |
| `update-user-application-role-connection` | `discord.updateUserApplicationRoleConnection()` | `--application-id` | 3 | Updates the application role connection for the currently authenticated user for a specified application |

## Triggers

`discord.on("<event>", handler)` in a script; required config goes before the handler as an object.

| Event | Name | Required config | Description |
|---|---|---|---|
| `"new-message"` | New Discord Message Trigger | `channel_id` | Polls a specific Discord channel for new messages |

## Docs

- [run CLI](https://docs.boxd.sh/cli/run): Call connected integrations from the shell, connect new ones, and run automations.
- [Quickstart](https://docs.boxd.sh/guides/integrations/quickstart): Connect an integration, call it from the shell, and turn a script into an automation.
- [Connections](https://docs.boxd.sh/guides/integrations/connections): Connect an account once, for yourself or for your whole organization.
- [Scripts](https://docs.boxd.sh/guides/automations/scripts): Typed integrations, triggers, schedules and state in a .run.ts file.
- [Jobs](https://docs.boxd.sh/guides/automations/jobs): How a script becomes a background job: states, retries, sleep and wake.
- [Beyond the catalog](https://docs.boxd.sh/guides/automations/beyond-the-catalog): Reach your own APIs, databases and cloud accounts from a script.
