# Discord

Discord access uses the Discord Gateway so users can DM the bot or mention it in a server channel to query status, control devices, or ask questions; server messages trigger only when the bot is mentioned, while DMs trigger directly.

## Usage Modes

| Mode | Trigger | Notes |
| --- | --- | --- |
| Bot DM | Send text directly to the bot | Good for personal status queries and remote control. |
| Server channel mention | Mention the bot in a channel and enter a question | Good for communities, developer servers, and team channels. |
| Long replies | Handled by the Device Agent automatically | Discord has per-message length limits, so long replies are split automatically. |

## Prepare the Discord App

1. Create an Application in Discord Developer Portal.
2. Open the Bot page and copy or reset the Bot Token.
3. Enable **Message Content Intent** on the Bot page.
4. Open OAuth2 → URL Generator:
   - Select `bot` under Scopes.
   - Select `View Channels`, `Send Messages`, and `Read Message History` under Bot Permissions.
5. Open the generated authorization URL and add the bot to the target server.

Do not only install the app from the Installation page. The invite URL must include `scope=bot`, or the app may not join as a bot.

## Configure Device Agent

Open **Settings → Channels → Discord** and fill in:

| Field | `.env` | Description |
| --- | --- | --- |
| Enabled | `DISCORD_ENABLED` | Starts the Discord channel |
| Bot Token | `DISCORD_BOT_TOKEN` | Discord Bot Token |
| Allow list | `DISCORD_ALLOW_FROM` | Optional Discord user Snowflake ID allow list |

You can also configure it in `.env`:

```bash
DISCORD_ENABLED=true
DISCORD_BOT_TOKEN=your-discord-bot-token
DISCORD_ALLOW_FROM=1234567890,2345678901
```

Restart the service after saving.

## Verify Access

1. Confirm the service has restarted.
2. Check logs for `Discord: enabled` and `Logged in as ...`.
3. Send a DM to the bot, or send `@Device Agent hello` in a server channel.
4. If the allow list is enabled, make sure the sender Snowflake ID is included.

Discord has per-message length limits. Long Device Agent replies are split automatically.

## Checks

- `Used disallowed intents`: enable **Message Content Intent** on the Bot page.
- No server channel response: mention the bot and confirm it can read and send messages.
- Allow list blocks messages: use user IDs, not usernames.
