# Discord API

`github.com/bwmarrin/discordgo` v0.29.0 を土台にした `github.com/pardnchiu/go-bot/core/discord` のすべての exported シンボルです。

## 型

| シンボル | 定義 | 備考 |
|---|---|---|
| `Bot` | `struct`（非公開フィールド） | `New` で作成する。メソッドは並行利用しても安全 |
| `Status` | `struct { Running bool; Username string; UserID string }` | `Status()` が返す |
| `Input` | `struct` | フィールド: `ChannelID`、`ChannelName`、`GuildID`、`MessageID`、`UserID`、`Username`、`Text`（すべて `string`）、`Attachments []*discordgo.MessageAttachment`、`CallbackPicks []string`、`Raw *discordgo.MessageCreate`。[Discord の設定](/ja/discord#input) を参照 |
| `ReplyHandler` | `func(ctx context.Context, input Input) string` | |
| `ChannelStatus` | `struct`（非公開フィールド） | `SendStatus` が管理するチャンネルごとのステータス項目。呼び出し側では作成しない |
| `StatusOption` | `func(*statusOptions)` | `SendStatus` のオプション |

## コンストラクタとオプション

| 関数 | 効果 |
|---|---|
| `New(token string) (*Bot, error)` | `token` が空の場合、または discordgo が拒否した場合にエラー |
| `WithStatusEmoji(emoji string) StatusOption` | リアクションの絵文字。デフォルトは `🤔` |

## メソッド

| メソッド | 戻り値 | エラーと制限 |
|---|---|---|
| `Start(ctx context.Context)` | `error` | `User("@me")` または `Session.Open` の失敗 |
| `Close()` | `error` | `Session.Close` の失敗 |
| `Status()` | `Status` | |
| `Reply(handler ReplyHandler)` | — | 以前の handler を置き換える |
| `Send(ctx, channelID, replyTo, text string)` | `(*discordgo.Message, error)` | 空のチャンネル ID、API のエラー |
| `Delete(ctx, channelID, messageID string)` | `error` | 空の ID、API のエラー |
| `SendFiles(ctx, channelID, replyTo string, paths []string, caption ...string)` | `(*discordgo.Message, error)` | 空のチャンネル ID、パスが 0 個または 10 個超、空のパス、`os.Open` の失敗 |
| `SendVoice(ctx, channelID, replyTo, path string, caption ...string)` | `(*discordgo.Message, error)` | 空のチャンネル ID またはパス、`os.Open` の失敗 |
| `SendInput(ctx, channelID, replyTo, prompt string)` | `(*discordgo.Message, error)` | 空のチャンネル ID またはプロンプト、UUID の失敗 |
| `SendSelect(ctx, channelID, replyTo, text string, items []string)` | `(*discordgo.Message, error)` | 空のチャンネル ID またはテキスト、空でない項目が 0 個または 25 個超、UUID の失敗 |
| `SendMultiSelect(ctx, channelID, replyTo, text string, items []string)` | `(*discordgo.Message, error)` | `SendSelect` と同じ |
| `SendStatus(ctx, channelID, replyTo, text string, opts ...StatusOption)` | `error` | 即座に flush した場合の送信 / 編集エラー |
| `FinishStatus(ctx, channelID string)` | `error` | 削除のエラー、または処理中の編集を待つ間の `ctx.Err()` |
| `Save(ctx, att *discordgo.MessageAttachment, dir string)` | `(string, error)` | nil の添付ファイル、空の URL または dir、25 MiB を超えるファイル、200 以外の HTTP ステータス、ファイルシステムのエラー |

## 関連ページ

[Discord の設定](/ja/discord) · [Discord メッセージ](/ja/discord-messages) · [Discord インタラクション](/ja/discord-interactions) · [ステータスメッセージ](/ja/status-messages) · [メディアの保存](/ja/media-save)
