# Discord API

Every exported symbol of `github.com/pardnchiu/go-bot/core/discord`, built on `github.com/bwmarrin/discordgo` v0.29.0.

## Types

| Symbol | Definition | Notes |
|---|---|---|
| `Bot` | `struct` (unexported fields) | Create with `New`; methods are safe for concurrent use |
| `Status` | `struct { Running bool; Username string; UserID string }` | Returned by `Status()` |
| `Input` | `struct` | Fields: `ChannelID`, `ChannelName`, `GuildID`, `MessageID`, `UserID`, `Username`, `Text` (all `string`), `Attachments []*discordgo.MessageAttachment`, `CallbackPicks []string`, `Raw *discordgo.MessageCreate`. See [Discord Setup](/discord#input) |
| `ReplyHandler` | `func(ctx context.Context, input Input) string` | |
| `ChannelStatus` | `struct` (unexported fields) | Per-channel status entry managed by `SendStatus`; not constructed by callers |
| `StatusOption` | `func(*statusOptions)` | Options for `SendStatus` |

## Constructor and options

| Function | Effect |
|---|---|
| `New(token string) (*Bot, error)` | Error when `token` is empty or discordgo rejects it |
| `WithStatusEmoji(emoji string) StatusOption` | Reaction emoji; default `🤔` |

## Methods

| Method | Returns | Errors and limits |
|---|---|---|
| `Start(ctx context.Context)` | `error` | `User("@me")` or `Session.Open` failure |
| `Close()` | `error` | `Session.Close` failure |
| `Status()` | `Status` | |
| `Reply(handler ReplyHandler)` | — | Replaces the previous handler |
| `Send(ctx, channelID, replyTo, text string)` | `(*discordgo.Message, error)` | Empty channel ID, API error |
| `Delete(ctx, channelID, messageID string)` | `error` | Empty IDs, API error |
| `SendFiles(ctx, channelID, replyTo string, paths []string, caption ...string)` | `(*discordgo.Message, error)` | Empty channel ID, 0 or more than 10 paths, empty path, `os.Open` failure |
| `SendVoice(ctx, channelID, replyTo, path string, caption ...string)` | `(*discordgo.Message, error)` | Empty channel ID or path, `os.Open` failure |
| `SendInput(ctx, channelID, replyTo, prompt string)` | `(*discordgo.Message, error)` | Empty channel ID or prompt, UUID failure |
| `SendSelect(ctx, channelID, replyTo, text string, items []string)` | `(*discordgo.Message, error)` | Empty channel ID or text, 0 or more than 25 non-empty items, UUID failure |
| `SendMultiSelect(ctx, channelID, replyTo, text string, items []string)` | `(*discordgo.Message, error)` | Same as `SendSelect` |
| `SendStatus(ctx, channelID, replyTo, text string, opts ...StatusOption)` | `error` | Send/edit error when flushed immediately |
| `FinishStatus(ctx, channelID string)` | `error` | Delete error, or `ctx.Err()` while waiting for an in-flight edit |
| `Save(ctx, att *discordgo.MessageAttachment, dir string)` | `(string, error)` | Nil attachment, empty URL or dir, file over 25 MiB, HTTP non-200, file system errors |

## Related pages

[Discord Setup](/discord) · [Discord Messages](/discord-messages) · [Discord Interactions](/discord-interactions) · [Status Messages](/status-messages) · [Saving Media](/media-save)
