# Discord Setup

This page covers constructing the `core/discord` bot, the gateway intents it requests, and the `Input` your handler receives.

## Constructor

```go
bot, err := discord.New(token)
```

`New` returns `token is required` for an empty token. It creates a `discordgo.Session` authenticated as `Bot <token>`, registers the message and interaction handlers, and does not connect. There are no options.

## Gateway intents

| Intent | Why it is requested |
|---|---|
| `IntentGuilds` | Makes the gateway send `GUILD_CREATE`, which fills discordgo's state cache; without it `Input.ChannelName` is always `""` |
| `IntentsGuildMessages` | Messages in server channels |
| `IntentDirectMessages` | Direct messages to the bot |
| `IntentMessageContent` | Message text and attachments |

`IntentMessageContent` is privileged. Enable **Message Content Intent** under Bot settings in the Discord Developer Portal; otherwise `Input.Text` is empty for most messages (Discord only sends content for DMs and messages that mention the bot).

## Start

`Start(ctx)` first calls REST `User("@me")` to validate the token, then `Session.Open()` to connect the WebSocket. A bad token fails at the first step, before any connection is opened. Messages sent by the bot itself are filtered using discordgo's session state, so they never reach the handler.

## Input

| Field | Type | Content |
|---|---|---|
| `ChannelID` | `string` | Channel of the message or prompt |
| `ChannelName` | `string` | Read from the state cache with no extra request; `""` for DMs or a cache miss |
| `GuildID` | `string` | Server ID; `""` for DMs |
| `MessageID` | `string` | The user's message; for modal and select answers, the prompt message |
| `UserID` / `Username` | `string` | Sender; for interactions, taken from the guild member or, in DMs, the user |
| `Text` | `string` | Message content, the modal answer, or the single-select pick |
| `Attachments` | `[]*discordgo.MessageAttachment` | Every uploaded file (images, files, audio); tell them apart with `ContentType` |
| `CallbackPicks` | `[]string` | Values chosen in a `SendMultiSelect` menu |
| `Raw` | `*discordgo.MessageCreate` | The SDK event for plain messages; `nil` for interaction answers |

All IDs are Discord snowflake strings.

## Related pages

- [Discord Messages](/discord-messages)
- [Discord Interactions](/discord-interactions)
- [Saving Media](/media-save)
- [Discord API](/api-reference-discord)
