# Discord

URL: https://swb.one/docs/setup/discord

SwB signs in to Discord as a bot. It gets new messages through the Discord Gateway, a connection that SwB opens to Discord.

## Before you start [#before-you-start]

Use a Discord account with **Manage Server** permission on the server you want to connect. Sign in to SwB as the owner.

## Copy the setup prompt [#copy-the-setup-prompt]

https://swb.one/prompts/discord.md

```
Read the setup guide at https://swb.one/docs/setup/discord.

Help me connect Discord to SwB. SwB carries messages between my agents and channels.

If the SwB tools are missing, ask me to add SwB as a custom MCP server. Follow https://swb.one/docs/connect to add the client.

For Claude, give me the path `Customize > Connectors > Add > Custom > Web`. For ChatGPT, ask me to open `https://chatgpt.com/plugins`. Give me the path `+ > Add custom MCP server`. For Grok, give me the path `grok.com > Connectors > New Connector > Custom`. For other apps, ask me to open the MCP server settings. Wait for me to confirm.

Use a SwB client with owner access.

Call `connect(what="discord")`. Do each step marked "you" yourself. Give me each step marked "person" one at a time with the exact click path and links. Wait for me to say done after each step.

Ask me to create an app at https://discord.com/developers/applications. Under **Bot**, ask me to generate its token. Ask me to turn on **Message Content Intent**. Ask me to enter the token only through the claim link from `connect`.

Add a space under `blocks.discord.spaces` in `config/switchboard.yaml`. Set `guild_id` to my Discord server ID and `owner_ids` to my user IDs. Grant the test agent access to the space in `blocks.discord.agents`. If the file needs a manual edit, give me the YAML. Restart SwB after an edit.

Read the invite link from `setup.invite_url` in `discord_status`. If the link is missing, set `blocks.discord.application_id` or wait for the bot to connect. Ask me to open the link and add the bot to my server. Call `connect` again to check the connection.

If Discord reports code `4014`, check **Message Content Intent**. If it reports code `4004`, replace the rejected token. When `connect` reports `connected`, ask me to choose a test channel. Call `discord_post` with the space label, channel ID and test text. Show me the result.

Subscribe to switchboard.message.created if this app supports MCP events. Otherwise, call wait or inbox to collect new messages.
```

Paste the prompt into your SwB owner client.

## Set up the Discord bot [#set-up-the-discord-bot]

### Create the application [#create-the-application]

Open https://discord.com/developers/applications. Click **New Application**.
### Name the application [#name-the-application]

Type a name. Click **Create**.
### Reset the bot token [#reset-the-bot-token]

Click **Bot** → **Reset Token**. Confirm the reset.

### Copy the bot token [#copy-the-bot-token]

Click **Copy** while Discord shows the token. Discord shows it only once.
### Turn on Message Content Intent [#turn-on-message-content-intent]

On the **Bot** page, turn on **Message Content Intent** under **Privileged Gateway Intents**. Click **Save Changes**.

### Save the token [#save-the-token]

Open the SwB claim link from your agent. Paste the token into the field.
### Invite the bot [#invite-the-bot]

Open the invite link from your agent. If Discord asks, select your server. Click **Authorize**.

## What the agent does [#what-the-agent-does]

The agent calls `connect(what="discord")`. If needed, it enables the `discord` block. When the block is enabled, `connect` or `discord_provision` returns a claim link for the bot token.

After you save the token, the agent calls `discord_status`. It checks the bot, the Gateway connection and the server. It gives you the invite link from `setup.invite_url`.

The agent configures the server under `blocks.discord.spaces` in `config/switchboard.yaml`. A space points a server to a SwB project. The agent sets `guild_id` and `owner_ids`. To let an agent call `discord_post`, grant it access under `blocks.discord.agents`. Restart SwB after editing the file.

## Credentials [#credentials]

| Token | Where Discord shows it | Format | Where it goes |
| --- | --- | --- | --- |
| Bot token | **Bot** → **Reset Token**, shown once | Three parts with dots between them | SwB claim link |
| Application ID | **General Information** → **Application ID** | A number | `blocks.discord.application_id`, or SwB finds it |

## Check the connection [#check-the-connection]

Ask the agent to call `connect` again. It reports `connected` when the setup is complete. `discord_status` shows that the Gateway is ready and the bot is on your server.

Use the Discord account listed in `owner_ids`. Mention the bot in a channel. Add a target name from `targets` and a test message. Check for the reply in the same channel.

## Fix problems [#fix-problems]

For Gateway code `4014`, enable **Message Content Intent**. To use mentions as the trigger, set `message_content: false` and mention the bot in each message.

For Gateway code `4004`, reset the Discord bot token. If the token comes from the server environment, replace it there and restart SwB. Otherwise, use a new claim link.

If the bot is on the server but stays quiet in a channel, check the permissions of that channel.
