v0.5.0

Discord API

Last updated


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

Types


SymbolDefinitionNotes
Botstruct (unexported fields)Create with New; methods are safe for concurrent use
Statusstruct { Running bool; Username string; UserID string }Returned by Status()
InputstructFields: ChannelID, ChannelName, GuildID, MessageID, UserID, Username, Text (all string), Attachments []*discordgo.MessageAttachment, CallbackPicks []string, Raw *discordgo.MessageCreate. See Discord Setup
ReplyHandlerfunc(ctx context.Context, input Input) string
ChannelStatusstruct (unexported fields)Per-channel status entry managed by SendStatus; not constructed by callers
StatusOptionfunc(*statusOptions)Options for SendStatus

Constructor and options


FunctionEffect
New(token string) (*Bot, error)Error when token is empty or discordgo rejects it
WithStatusEmoji(emoji string) StatusOptionReaction emoji; default 🤔

Methods


MethodReturnsErrors and limits
Start(ctx context.Context)errorUser("@me") or Session.Open failure
Close()errorSession.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)errorEmpty 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)errorSend/edit error when flushed immediately
FinishStatus(ctx, channelID string)errorDelete 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


Discord Setup · Discord Messages · Discord Interactions · Status Messages · Saving Media
中文