Documentation
¶
Overview ¶
Package dc is the bot's internal Discord facade.
Every type here is library-neutral: it mirrors the shape of the Discord API rather than the shape of any Go client. Handlers, command definitions and message payloads are expressed in these types, and this package alone converts them to whatever client is linked in.
It converts to github.com/disgoorg/disgo. Swapping the client out replaced the internals of this package only; call sites in the rest of the bot were left untouched.
The facade grows on demand. Only the pieces a migrated package needs are modelled, so an absent type means "not migrated yet", not "unsupported".
Index ¶
- Constants
- Variables
- func CustomID(parts ...string) string
- func IsMissingAccess(err error) bool
- func IsMissingPermissions(err error) bool
- func IsSnowflake(s string) bool
- func IsThreadArchived(err error) bool
- func IsUnknownChannel(err error) bool
- func IsUnknownMember(err error) bool
- func IsUnknownMessage(err error) bool
- func SnowflakeTimestamp(id string) (time.Time, error)
- func SplitContractHash(id string) string
- func SplitCustomID(id string) []string
- type APIError
- type ActionRow
- type AllowedMentions
- type Attachment
- type AttachmentOption
- type AutocompleteEvent
- func (e *AutocompleteEvent) ChannelID() string
- func (e *AutocompleteEvent) CommandName() string
- func (e *AutocompleteEvent) FocusedOption() (name string, value string)
- func (e *AutocompleteEvent) GuildID() string
- func (e *AutocompleteEvent) OptString(name string) (string, bool)
- func (e *AutocompleteEvent) RespondChoices(choices []Choice[string]) (err error)
- func (e *AutocompleteEvent) RespondChoicesInt(choices []Choice[int]) (err error)
- func (e *AutocompleteEvent) Subcommand() (string, bool)
- func (e *AutocompleteEvent) UserID() string
- type BoolOption
- type Bot
- func (b *Bot) Client() Client
- func (b *Bot) Close() error
- func (b *Bot) CommandNames() []string
- func (b *Bot) Connect(token string, intents Intents) error
- func (b *Bot) OnAutocomplete(name string, handler func(*AutocompleteEvent))
- func (b *Bot) OnCommand(name string, handler func(*CommandEvent))
- func (b *Bot) OnComponent(prefix string, handler func(*ComponentEvent))
- func (b *Bot) OnMessage(handler func(*MessageEvent))
- func (b *Bot) OnModal(prefix string, handler func(*ModalEvent))
- func (b *Bot) OnPanic(handler func(recovered any, meta InteractionMeta))
- func (b *Bot) OnReactionAdd(handler func(*ReactionEvent))
- func (b *Bot) OnReactionRemove(handler func(*ReactionEvent))
- func (b *Bot) OnReady(handler func())
- func (b *Bot) OnUnknown(handler func(*UnknownEvent))
- func (b *Bot) Open() error
- func (b *Bot) SetPresence(activity string) error
- func (b *Bot) UserID() string
- type Button
- type ButtonStyle
- type Channel
- type ChannelOption
- type ChannelType
- type Choice
- type Client
- type Command
- type CommandEvent
- func (e *CommandEvent) ApplicationID() string
- func (e *CommandEvent) AvatarURL() string
- func (e *CommandEvent) ChannelID() string
- func (e *CommandEvent) Client() Client
- func (e *CommandEvent) CommandName() string
- func (e *CommandEvent) Defer(ephemeral bool) (err error)
- func (e *CommandEvent) DeleteFollowup(messageID string) error
- func (e *CommandEvent) EditFollowup(messageID string, m Message) error
- func (e *CommandEvent) EditResponse(m Message) error
- func (e *CommandEvent) Followup(m Message) error
- func (e *CommandEvent) FollowupMessage(m Message) (*MessageRef, error)
- func (e *CommandEvent) FromComponent() bool
- func (e *CommandEvent) GuildID() string
- func (e *CommandEvent) HasOption(name string) bool
- func (e *CommandEvent) Member() *Member
- func (e *CommandEvent) MessageContent() string
- func (e *CommandEvent) MessageID() string
- func (e *CommandEvent) OptAttachment(name string) (*Attachment, bool)
- func (e *CommandEvent) OptBool(name string) (bool, bool)
- func (e *CommandEvent) OptChannel(name string) (string, bool)
- func (e *CommandEvent) OptInt(name string) (int, bool)
- func (e *CommandEvent) OptString(name string) (string, bool)
- func (e *CommandEvent) OptUser(name string) (*User, bool)
- func (e *CommandEvent) OptionSummary() map[string]string
- func (e *CommandEvent) Options() OptionValues
- func (e *CommandEvent) Respond(m Message) (err error)
- func (e *CommandEvent) ShowModal(modal Modal) (err error)
- func (e *CommandEvent) Subcommand() (string, bool)
- func (e *CommandEvent) SubcommandPath() []string
- func (e *CommandEvent) Token() string
- func (e *CommandEvent) User() *User
- func (e *CommandEvent) UserID() string
- type CommandRef
- type ComponentEvent
- func (e *ComponentEvent) ApplicationID() string
- func (e *ComponentEvent) AvatarURL() string
- func (e *ComponentEvent) ChannelID() string
- func (e *ComponentEvent) Client() Client
- func (e *ComponentEvent) CustomID() string
- func (e *ComponentEvent) Defer(ephemeral bool) (err error)
- func (e *ComponentEvent) DeferUpdate() (err error)
- func (e *ComponentEvent) DeleteResponse() error
- func (e *ComponentEvent) EditFollowup(messageID string, m Message) error
- func (e *ComponentEvent) EditResponse(m Message) error
- func (e *ComponentEvent) Followup(m Message) error
- func (e *ComponentEvent) FollowupMessage(m Message) (*MessageRef, error)
- func (e *ComponentEvent) FromComponent() bool
- func (e *ComponentEvent) GuildID() string
- func (e *ComponentEvent) Member() *Member
- func (e *ComponentEvent) MessageComponentsWithoutActionRows() []LayoutComponent
- func (e *ComponentEvent) MessageContent() string
- func (e *ComponentEvent) MessageID() string
- func (e *ComponentEvent) MessageIsEphemeral() bool
- func (e *ComponentEvent) Respond(m Message) (err error)
- func (e *ComponentEvent) ShowModal(modal Modal) (err error)
- func (e *ComponentEvent) Token() string
- func (e *ComponentEvent) Update(m Message) (err error)
- func (e *ComponentEvent) User() *User
- func (e *ComponentEvent) UserID() string
- func (e *ComponentEvent) Values() []string
- type Container
- type ContainerSubComponent
- type Embed
- type EmbedAuthor
- type EmbedField
- type EmbedFooter
- type Emoji
- type EmojiParams
- type File
- type Guild
- type IntOption
- type IntegrationType
- type Intents
- type InteractionContext
- type InteractionEvent
- type InteractionKind
- type InteractionMeta
- type InteractiveComponent
- type LayoutComponent
- type MediaGallery
- type MediaItem
- type Member
- type MentionType
- type Message
- type MessageEditDebouncer
- type MessageEvent
- type MessageRef
- type Modal
- type ModalEvent
- func (e *ModalEvent) AvatarURL() string
- func (e *ModalEvent) ChannelID() string
- func (e *ModalEvent) Client() Client
- func (e *ModalEvent) CustomID() string
- func (e *ModalEvent) Defer(ephemeral bool) (err error)
- func (e *ModalEvent) DeferUpdate() (err error)
- func (e *ModalEvent) EditFollowup(messageID string, m Message) error
- func (e *ModalEvent) EditResponse(m Message) error
- func (e *ModalEvent) Followup(m Message) error
- func (e *ModalEvent) FollowupMessage(m Message) (*MessageRef, error)
- func (e *ModalEvent) FromComponent() bool
- func (e *ModalEvent) GuildID() string
- func (e *ModalEvent) Member() *Member
- func (e *ModalEvent) MessageContent() string
- func (e *ModalEvent) MessageID() string
- func (e *ModalEvent) Respond(m Message) (err error)
- func (e *ModalEvent) ShowModal(modal Modal) error
- func (e *ModalEvent) TextValue(customID string) string
- func (e *ModalEvent) Update(m Message) (err error)
- func (e *ModalEvent) User() *User
- func (e *ModalEvent) UserID() string
- type NumberOption
- type Option
- type OptionValues
- func (o OptionValues) Attachment(name string) (*Attachment, bool)
- func (o OptionValues) Bool(name string) (bool, bool)
- func (o OptionValues) Float(name string) (float64, bool)
- func (o OptionValues) Int(name string) (int, bool)
- func (o OptionValues) String(name string) (string, bool)
- func (o OptionValues) Subcommand() (string, bool)
- func (o OptionValues) SubcommandPath() []string
- func (o OptionValues) Uint(name string) (uint64, bool)
- func (o OptionValues) User(name string) (*User, bool)
- type Permissions
- type ReactionEvent
- type Role
- type RoleOption
- type RoleParams
- type Section
- type SectionAccessory
- type SelectMenu
- type SelectOption
- type Separator
- type SeparatorSpacing
- type StringOption
- type SubCommand
- type SubCommandGroup
- type TextDisplay
- type TextInput
- type TextInputStyle
- type ThreadMember
- type Thumbnail
- type UnknownEvent
- type User
- type UserOption
Constants ¶
const ( // PermissionAdministrator is the administrator permission bit. PermissionAdministrator int64 = int64(discord.PermissionAdministrator) // PermissionManageGuild is the "Manage Server" permission bit. PermissionManageGuild int64 = int64(discord.PermissionManageGuild) )
Permission bits for Command.DefaultMemberPermissions, which restricts who Discord offers a command to by default. Named here so callers do not need to import discordgo.
const ( // ErrCodeUnknownChannel means the channel no longer exists. ErrCodeUnknownChannel = 10003 // ErrCodeUnknownMember means the user is not a member of the guild. ErrCodeUnknownMember = 10007 // ErrCodeUnknownMessage means the message no longer exists. ErrCodeUnknownMessage = 10008 // ErrCodeMissingAccess means the bot cannot see the channel at all. ErrCodeMissingAccess = 50001 // ErrCodeMissingPermissions means the bot can see the channel but is not // allowed the action it attempted. ErrCodeMissingPermissions = 50013 // ErrCodeThreadArchived means the thread is archived and must be unarchived // before messages can be sent to it. ErrCodeThreadArchived = 50083 )
Discord JSON error codes the bot reacts to. Discord returns these in the body of a failed REST call, alongside the HTTP status.
const DefaultEditDebounceWindow = 500 * time.Millisecond
DefaultEditDebounceWindow is the duration rapid edits to the same message are debounced.
Variables ¶
var ErrWrongInteractionResponse = errors.New("dc: this interaction cannot be answered that way")
ErrWrongInteractionResponse is returned when an interaction is answered in a way Discord does not allow for its kind, such as opening a modal in reply to a modal submission.
Functions ¶
func CustomID ¶
CustomID joins parts into the bot's "prefix#arg#...#contractHash" convention for button, select menu and modal CustomIDs. It panics if any part contains the separator: that convention is load-bearing across every message the bot has already posted, and a silently malformed ID is worse than a crash caught in tests.
func IsMissingAccess ¶
IsMissingAccess reports whether err is Discord refusing a call because the bot cannot view/access the target channel or guild (Discord code 50001).
func IsMissingPermissions ¶
IsMissingPermissions reports whether err is Discord refusing a call because the bot lacks specific permissions to perform the action (Discord code 50013).
func IsSnowflake ¶
IsSnowflake reports whether s is a valid Discord snowflake ID.
func IsThreadArchived ¶
IsThreadArchived reports whether err is Discord refusing a message send because the target thread is archived.
func IsUnknownChannel ¶
IsUnknownChannel reports whether err is Discord refusing a call because the channel is gone. A bare 404 counts: Discord does not always include an error code, and for a channel-scoped call there is nothing else it can mean.
func IsUnknownMember ¶
IsUnknownMember reports whether err is Discord refusing a call because the user is not in the guild. A 404 status code or code 10007 counts.
func IsUnknownMessage ¶
IsUnknownMessage reports whether err is Discord refusing a call because the message is gone — deleted, or posted by a bot whose messages were purged.
func SnowflakeTimestamp ¶
SnowflakeTimestamp is the creation time encoded in a Discord ID.
func SplitContractHash ¶
SplitContractHash extracts the trailing contract hash (the last segment after the final "#") from a CustomID. If no separator is present, it returns the entire id.
func SplitCustomID ¶
SplitCustomID reverses CustomID, returning the segments in order.
Types ¶
type APIError ¶
APIError is a rejected Discord REST call. Code is Discord's own error code from the response body and is zero when Discord sent no parsable body.
func AsAPIError ¶
AsAPIError reports whether err came from a rejected Discord REST call, and if so translates it. It unwraps, so a wrapped error still matches.
type ActionRow ¶
type ActionRow struct {
Components []InteractiveComponent
}
ActionRow is a row of up to five interactive components. Unlike most components here it can appear both at the top level of a message and nested inside a Container.
type AllowedMentions ¶
type AllowedMentions struct {
Parse []MentionType
Users []string
Roles []string
}
AllowedMentions controls which mentions in a message actually notify.
A nil *AllowedMentions leaves Discord's default behavior in place. A non-nil AllowedMentions with an empty Parse list suppresses all mentions.
type Attachment ¶
type Attachment struct {
ID string
Filename string
URL string
ProxyURL string
ContentType string
Size int
}
Attachment is a file a user attached to a command or a message.
type AttachmentOption ¶
AttachmentOption is a command parameter that resolves to an uploaded file.
type AutocompleteEvent ¶
type AutocompleteEvent struct {
LastChoices []Choice[string]
// contains filtered or unexported fields
}
AutocompleteEvent wraps an autocomplete interaction event and records choices.
func NewAutocompleteEventFromPayload ¶
func NewAutocompleteEventFromPayload(payload []byte) (*AutocompleteEvent, error)
NewAutocompleteEventFromPayload builds an AutocompleteEvent from Discord's own interaction JSON.
func (*AutocompleteEvent) ChannelID ¶
func (e *AutocompleteEvent) ChannelID() string
ChannelID is the channel the command is being typed in.
func (*AutocompleteEvent) CommandName ¶
func (e *AutocompleteEvent) CommandName() string
CommandName is the command the option being completed belongs to.
func (*AutocompleteEvent) FocusedOption ¶
func (e *AutocompleteEvent) FocusedOption() (name string, value string)
FocusedOption is the option the user is currently typing into, which is the one the suggestions are for.
func (*AutocompleteEvent) GuildID ¶
func (e *AutocompleteEvent) GuildID() string
GuildID is the guild the command is being typed in, empty in a DM.
func (*AutocompleteEvent) OptString ¶
func (e *AutocompleteEvent) OptString(name string) (string, bool)
OptString reads a string option already filled in on the command being completed, which is how one option's suggestions depend on another.
func (*AutocompleteEvent) RespondChoices ¶
func (e *AutocompleteEvent) RespondChoices(choices []Choice[string]) (err error)
RespondChoices answers with the suggestion list. An empty list is the way to say "no suggestions".
func (*AutocompleteEvent) RespondChoicesInt ¶
func (e *AutocompleteEvent) RespondChoicesInt(choices []Choice[int]) (err error)
RespondChoicesInt answers an integer option's autocomplete.
func (*AutocompleteEvent) Subcommand ¶
func (e *AutocompleteEvent) Subcommand() (string, bool)
Subcommand is the subcommand being completed under, false when there is none.
func (*AutocompleteEvent) UserID ¶
func (e *AutocompleteEvent) UserID() string
UserID is the user typing the command.
type BoolOption ¶
BoolOption is a boolean command parameter.
type Bot ¶
type Bot struct {
// contains filtered or unexported fields
}
Bot is the gateway connection plus the interaction routing table.
Routing matches what the bot did before the facade existed: commands and autocomplete route on the command name, components and modals route on the segment of the CustomID before the first "#". disgo ships a handler.Router that would do the same job, but its paths are "/"-delimited, which would invalidate the "#"-delimited CustomIDs already sitting on posted messages.
func NewBot ¶
func NewBot() *Bot
NewBot returns a Bot with an empty routing table and no gateway session. Use Connect to attach one.
func (*Bot) Close ¶
Close disconnects from the gateway. disgo's shutdown reports no error, so the error return exists only to keep the facade's shape.
func (*Bot) CommandNames ¶
CommandNames lists every registered command name, sorted, so command sync produces a stable order.
func (*Bot) Connect ¶
Connect builds the gateway client for a bot token and wires interaction dispatch to the routing table. It does not open the connection; call Open.
The gateway listeners are fixed at build time, so every On* hook has to be registered before this runs.
func (*Bot) OnAutocomplete ¶
func (b *Bot) OnAutocomplete(name string, handler func(*AutocompleteEvent))
OnAutocomplete registers the autocomplete handler for a slash command name.
func (*Bot) OnCommand ¶
func (b *Bot) OnCommand(name string, handler func(*CommandEvent))
OnCommand registers the handler for a slash command name.
func (*Bot) OnComponent ¶
func (b *Bot) OnComponent(prefix string, handler func(*ComponentEvent))
OnComponent registers the handler for every component CustomID starting with prefix, where prefix is the segment before the first "#".
func (*Bot) OnMessage ¶
func (b *Bot) OnMessage(handler func(*MessageEvent))
OnMessage registers a handler for every message the bot can see. Call it before Connect.
func (*Bot) OnModal ¶
func (b *Bot) OnModal(prefix string, handler func(*ModalEvent))
OnModal registers the handler for every modal CustomID starting with prefix.
func (*Bot) OnPanic ¶
func (b *Bot) OnPanic(handler func(recovered any, meta InteractionMeta))
OnPanic registers the recovery hook for panics raised inside handlers. Without one, a panicking handler takes the process down.
func (*Bot) OnReactionAdd ¶
func (b *Bot) OnReactionAdd(handler func(*ReactionEvent))
OnReactionAdd registers a handler for reactions added to any message the bot can see, including its own. Call it before Connect.
func (*Bot) OnReactionRemove ¶
func (b *Bot) OnReactionRemove(handler func(*ReactionEvent))
OnReactionRemove registers a handler for reactions taken back off a message. Call it before Connect.
func (*Bot) OnReady ¶
func (b *Bot) OnReady(handler func())
OnReady registers a callback run once the gateway reports ready. Call it before Connect.
func (*Bot) OnUnknown ¶
func (b *Bot) OnUnknown(handler func(*UnknownEvent))
OnUnknown registers the fallback for interactions with no registered route, which is how the bot answers stale buttons on old messages.
func (*Bot) SetPresence ¶
SetPresence sets the bot's activity to "Playing <activity>".
type Button ¶
type Button struct {
Label string
CustomID string
Style ButtonStyle
URL string
Disabled bool
Emoji *Emoji
}
Button is a clickable component that lives inside an ActionRow, or as a Section's accessory.
A Button styled ButtonLink carries a URL instead of a CustomID; Discord rejects a button that sets both.
type ButtonStyle ¶
type ButtonStyle int
ButtonStyle is the visual style of a Button.
const ( ButtonPrimary ButtonStyle = iota ButtonSecondary ButtonSuccess ButtonDanger ButtonLink )
Button styles.
type Channel ¶
type Channel struct {
ID string
GuildID string
Name string
ParentID string
LastMessageID string
IsThread bool
// IsCategory is true for the container channels other channels are
// grouped under.
IsCategory bool
}
Channel is a Discord channel or thread.
type ChannelOption ¶
type ChannelOption struct {
Name string
Description string
Required bool
ChannelTypes []ChannelType
}
ChannelOption is a command parameter that resolves to a channel. An empty ChannelTypes lets the user pick any channel.
type ChannelType ¶
type ChannelType int
ChannelType is a kind of Discord channel. Only the kinds this bot restricts a ChannelOption to are modeled; add more as commands need them.
const ( ChannelText ChannelType = iota ChannelNews ChannelForum )
Channel kinds a ChannelOption can be limited to.
type Choice ¶
Choice is one selectable value of a StringOption, IntOption or NumberOption. Value is limited to the types Discord accepts for choices.
type Client ¶
type Client interface {
// SendMessage posts a new message to a channel.
SendMessage(channelID string, m Message) (*MessageRef, error)
// EditMessage replaces the content of an existing message.
EditMessage(channelID, messageID string, m Message) (*MessageRef, error)
// DeleteMessage removes a message.
DeleteMessage(channelID, messageID string) error
// GetMessage fetches a single message.
GetMessage(channelID, messageID string) (*MessageRef, error)
// PinMessage pins a message to its channel.
PinMessage(channelID, messageID string) error
// UnpinMessage unpins a message from its channel.
UnpinMessage(channelID, messageID string) error
// Typing sends a typing indicator to a channel.
Typing(channelID string) error
// Channel fetches a channel or thread by ID.
Channel(channelID string) (*Channel, error)
// EditChannel renames a channel or thread.
EditChannel(channelID, name string) (*Channel, error)
// GuildChannels lists every channel in a guild.
GuildChannels(guildID string) ([]Channel, error)
// Guild fetches a guild by ID.
Guild(guildID string) (*Guild, error)
// GuildMember fetches a user's guild-scoped identity.
GuildMember(guildID, userID string) (*Member, error)
// GuildMemberWithColor fetches a member along with the color their highest
// colored role gives them in a channel. The color comes from the gateway
// state cache, which the fetched member is recorded in first so a member
// the bot has not seen still resolves. The color is 0 when the state
// cannot supply one.
GuildMemberWithColor(guildID, userID, channelID string) (*Member, int, error)
// GuildRoles lists every role in a guild.
GuildRoles(guildID string) ([]Role, error)
// CreateGuildRole creates a new guild role.
CreateGuildRole(guildID string, params RoleParams) (*Role, error)
// EditGuildRole updates an existing guild role.
EditGuildRole(guildID, roleID string, params RoleParams) (*Role, error)
// DeleteGuildRole deletes a guild role.
DeleteGuildRole(guildID, roleID string) error
// AddGuildMemberRole grants a role to a guild member.
AddGuildMemberRole(guildID, userID, roleID string) error
// RemoveGuildMemberRole revokes a role from a guild member.
RemoveGuildMemberRole(guildID, userID, roleID string) error
// BotUsername is the display name of the account the bot is signed in as.
// It is empty until the gateway connection reports the account.
BotUsername() string
// BotAvatarURL is the bot's own avatar at the requested pixel size, such
// as "256". It is empty until the gateway connection reports the account.
BotAvatarURL(size string) string
// User fetches an account by ID.
User(userID string) (*User, error)
// CreateUserChannel opens (or fetches the existing) DM channel with a user.
CreateUserChannel(userID string) (*Channel, error)
// UserChannelPermissions computes a user's effective permissions in a channel.
UserChannelPermissions(userID, channelID string) (Permissions, error)
// RemoveMessageReaction removes one user's reaction from a message.
RemoveMessageReaction(channelID, messageID, emojiID, userID string) error
// StartThread creates a public thread under a channel.
StartThread(channelID, name string, archiveDurationMinutes int) (*Channel, error)
// JoinThread adds the bot to a thread.
JoinThread(channelID string) error
// AddThreadMember adds a member to a thread.
AddThreadMember(threadID, userID string) error
// ThreadMember fetches a thread member by thread and user ID.
ThreadMember(threadID, userID string) (*ThreadMember, error)
// ActiveThreads lists the active threads in a guild. Discord's
// active-threads endpoint is guild-scoped, so callers that want the
// threads under one channel filter the result on ParentID.
ActiveThreads(guildID string) ([]Channel, error)
// SetStatus sets the bot's presence to "Playing <activityName>".
SetStatus(activityName string) error
// ApplicationCommands lists the commands currently registered for an app,
// scoped to a guild (empty guildID means the global command set).
ApplicationCommands(appID, guildID string) ([]CommandRef, error)
// DeleteApplicationCommand removes one registered command.
DeleteApplicationCommand(appID, guildID, commandID string) error
// BulkOverwriteApplicationCommands replaces an app's entire command set in
// one call.
BulkOverwriteApplicationCommands(appID, guildID string, commands []Command) ([]CommandRef, error)
// ApplicationEmojis lists the emoji uploaded to an application.
ApplicationEmojis(appID string) ([]Emoji, error)
// ApplicationEmojiCreate uploads one emoji to an application.
ApplicationEmojiCreate(appID string, params EmojiParams) (*Emoji, error)
// EditInteractionResponse replaces the interaction's original response or updated message.
EditInteractionResponse(appID, token string, m Message) error
// EditFollowupMessage replaces an interaction's followup message.
EditFollowupMessage(appID, token, messageID string, m Message) error
}
Client is the bot's REST surface onto Discord: everything outside an interaction (see event.go for interaction-scoped calls such as responding to a command).
type Command ¶
type Command struct {
Name string
Description string
Contexts []InteractionContext
IntegrationTypes []IntegrationType
Options []Option
DefaultMemberPermissions *int64
// GuildID scopes the command to one guild instead of publishing it
// globally. Empty means global, which is the usual case.
GuildID string
}
Command is a slash command definition.
func (Command) ToDisgo ¶
func (c Command) ToDisgo() discord.ApplicationCommandCreate
ToDisgo renders the command as the payload disgo publishes. GuildID has no counterpart in the payload: disgo scopes a command by which REST call registers it, so the caller reads Command.GuildID itself.
type CommandEvent ¶
type CommandEvent struct {
LastResponse *Message
LastFollowup *Message
Followups []Message
// contains filtered or unexported fields
}
CommandEvent is one slash command invocation: the interaction plus the means to answer it. Handlers take this instead of a client and an event.
func NewCommandEventFromPayload ¶
func NewCommandEventFromPayload(payload []byte) (*CommandEvent, error)
NewCommandEventFromPayload builds a CommandEvent from Discord's own interaction JSON.
disgo keeps an interaction's identity fields unexported and fills them in while decoding, so the wire payload is the only way to construct one. Tests use this to exercise option parsing without a gateway; it is also what an HTTP-interaction transport would need.
func (*CommandEvent) ApplicationID ¶
func (e *CommandEvent) ApplicationID() string
ApplicationID returns the interaction's application ID.
func (*CommandEvent) AvatarURL ¶
func (e *CommandEvent) AvatarURL() string
AvatarURL returns the user's effective avatar URL, preferring their guild member avatar when invoked within a guild, and falling back to their account avatar.
func (*CommandEvent) ChannelID ¶
func (e *CommandEvent) ChannelID() string
ChannelID is the channel the command was run in.
func (*CommandEvent) Client ¶
func (e *CommandEvent) Client() Client
Client returns the bot's REST client, or nil if none is attached.
func (*CommandEvent) CommandName ¶
func (e *CommandEvent) CommandName() string
CommandName is the name the command was invoked under. A single handler can back several names, so this is how it tells them apart.
func (*CommandEvent) Defer ¶
func (e *CommandEvent) Defer(ephemeral bool) (err error)
Defer acknowledges the interaction without answering it, which buys past Discord's three second deadline. Answer afterwards with Followup.
func (*CommandEvent) DeleteFollowup ¶
func (e *CommandEvent) DeleteFollowup(messageID string) error
DeleteFollowup deletes a followup message this interaction already sent.
func (*CommandEvent) EditFollowup ¶
func (e *CommandEvent) EditFollowup(messageID string, m Message) error
EditFollowup edits a followup message this interaction already sent.
func (*CommandEvent) EditResponse ¶
func (e *CommandEvent) EditResponse(m Message) error
EditResponse replaces the interaction's original response.
func (*CommandEvent) Followup ¶
func (e *CommandEvent) Followup(m Message) error
Followup sends a message after the interaction has been deferred or already answered.
func (*CommandEvent) FollowupMessage ¶
func (e *CommandEvent) FollowupMessage(m Message) (*MessageRef, error)
FollowupMessage sends a followup and returns the message it created, for a caller that needs to edit or delete it later.
func (*CommandEvent) FromComponent ¶
func (e *CommandEvent) FromComponent() bool
FromComponent is false: a command interaction has no message on screen.
func (*CommandEvent) GuildID ¶
func (e *CommandEvent) GuildID() string
GuildID is the guild the command was run in, empty in a DM.
func (*CommandEvent) HasOption ¶
func (e *CommandEvent) HasOption(name string) bool
HasOption reports whether the user supplied an option, whatever its value. It separates "the user left this out" from "the value did not come through", which the typed readers collapse into one false.
func (*CommandEvent) Member ¶
func (e *CommandEvent) Member() *Member
Member is the guild-scoped identity of the user who ran the command, nil in a DM where there is no membership.
func (*CommandEvent) MessageContent ¶
func (e *CommandEvent) MessageContent() string
MessageContent is always empty for a command interaction, which is not attached to a message.
func (*CommandEvent) MessageID ¶
func (e *CommandEvent) MessageID() string
MessageID is empty for a command interaction, which has no source message.
func (*CommandEvent) OptAttachment ¶
func (e *CommandEvent) OptAttachment(name string) (*Attachment, bool)
OptAttachment reads an attachment option, resolving it against the interaction's attachment table. The second return is false when the user did not supply the option or Discord sent no matching attachment.
func (*CommandEvent) OptBool ¶
func (e *CommandEvent) OptBool(name string) (bool, bool)
OptBool reads a boolean option.
func (*CommandEvent) OptChannel ¶
func (e *CommandEvent) OptChannel(name string) (string, bool)
OptChannel reads a channel option and returns the channel's ID. The channel is identified by ID alone because that is what every caller passes on to Discord; the resolved channel object is not carried through the facade. The second return is false when the user did not supply the option.
func (*CommandEvent) OptInt ¶
func (e *CommandEvent) OptInt(name string) (int, bool)
OptInt reads an integer option. The second return is false when the user did not supply the option.
func (*CommandEvent) OptString ¶
func (e *CommandEvent) OptString(name string) (string, bool)
OptString reads a string option.
func (*CommandEvent) OptUser ¶
func (e *CommandEvent) OptUser(name string) (*User, bool)
OptUser reads a user option, resolved from the data Discord sends with the interaction. The second return is false when the user did not supply the option or Discord did not resolve it.
func (*CommandEvent) OptionSummary ¶
func (e *CommandEvent) OptionSummary() map[string]string
OptionSummary is a flat name-to-text view of the options the user filled in, for logging. A user option renders as the username, and an option type it does not know becomes "Unknown".
func (*CommandEvent) Options ¶
func (e *CommandEvent) Options() OptionValues
Options snapshots the options this command was invoked with.
func (*CommandEvent) Respond ¶
func (e *CommandEvent) Respond(m Message) (err error)
Respond answers the interaction with a new message.
func (*CommandEvent) ShowModal ¶
func (e *CommandEvent) ShowModal(modal Modal) (err error)
ShowModal answers the interaction by opening a modal form.
func (*CommandEvent) Subcommand ¶
func (e *CommandEvent) Subcommand() (string, bool)
Subcommand is the name of the subcommand the user invoked, for commands that group their behavior that way. The second return is false when the command was invoked with no subcommand.
disgo lifts the subcommand out of the option tree while decoding, so the outermost name is the group when there is one and the subcommand otherwise.
func (*CommandEvent) SubcommandPath ¶
func (e *CommandEvent) SubcommandPath() []string
SubcommandPath is the full path of the invoked subcommand, outermost first. A command grouped as `/update contract coop-id` returns ["contract", "coop-id"]; a command with a single level of subcommands returns one element; a command invoked with no subcommand returns nil.
func (*CommandEvent) Token ¶
func (e *CommandEvent) Token() string
Token returns the interaction's token.
func (*CommandEvent) User ¶
func (e *CommandEvent) User() *User
User is the account that ran the command.
func (*CommandEvent) UserID ¶
func (e *CommandEvent) UserID() string
UserID is the ID of the user who ran the command, in a guild or a DM.
type CommandRef ¶
CommandRef identifies a slash command already registered with Discord, as returned by Client.ApplicationCommands and Client.BulkOverwriteApplicationCommands. Unlike Command, which describes a command definition to be published, CommandRef carries the ID Discord assigned it.
type ComponentEvent ¶
type ComponentEvent struct {
LastResponse *Message
// contains filtered or unexported fields
}
ComponentEvent is one button press or select menu choice.
func NewComponentEventFromPayload ¶
func NewComponentEventFromPayload(payload []byte) (*ComponentEvent, error)
NewComponentEventFromPayload builds a ComponentEvent from Discord's own interaction JSON.
func (*ComponentEvent) ApplicationID ¶
func (e *ComponentEvent) ApplicationID() string
ApplicationID returns the interaction's application ID.
func (*ComponentEvent) AvatarURL ¶
func (e *ComponentEvent) AvatarURL() string
AvatarURL returns the user's effective avatar URL, preferring their guild member avatar when invoked within a guild, and falling back to their account avatar.
func (*ComponentEvent) ChannelID ¶
func (e *ComponentEvent) ChannelID() string
ChannelID is the channel the interaction was sent from.
func (*ComponentEvent) Client ¶
func (e *ComponentEvent) Client() Client
Client returns the bot's REST client, or nil if none is attached.
func (*ComponentEvent) CustomID ¶
func (e *ComponentEvent) CustomID() string
CustomID is the component's identifier, which carries this bot's "prefix#arg#...#contractHash" routing data.
func (*ComponentEvent) Defer ¶
func (e *ComponentEvent) Defer(ephemeral bool) (err error)
Defer acknowledges the interaction and promises a new message rather than an edit of the existing one.
func (*ComponentEvent) DeferUpdate ¶
func (e *ComponentEvent) DeferUpdate() (err error)
DeferUpdate acknowledges the interaction and leaves the message as it is, which is how a handler takes its time before redrawing.
func (*ComponentEvent) DeleteResponse ¶
func (e *ComponentEvent) DeleteResponse() error
DeleteResponse deletes the interaction's original response.
func (*ComponentEvent) EditFollowup ¶
func (e *ComponentEvent) EditFollowup(messageID string, m Message) error
EditFollowup edits a followup message this interaction already sent. When passed the component's own source message ID, "@original", or an empty ID, it edits the original interaction response instead, matching Discord's requirement that the message hosting a component is updated via @original.
func (*ComponentEvent) EditResponse ¶
func (e *ComponentEvent) EditResponse(m Message) error
EditResponse replaces the interaction's original response.
func (*ComponentEvent) Followup ¶
func (e *ComponentEvent) Followup(m Message) error
Followup sends a message after the interaction has been deferred or already answered.
func (*ComponentEvent) FollowupMessage ¶
func (e *ComponentEvent) FollowupMessage(m Message) (*MessageRef, error)
FollowupMessage sends a followup and returns the message it created.
func (*ComponentEvent) FromComponent ¶
func (e *ComponentEvent) FromComponent() bool
FromComponent is true: a component interaction has a message on screen.
func (*ComponentEvent) GuildID ¶
func (e *ComponentEvent) GuildID() string
GuildID is the guild the interaction was sent from, empty in a DM.
func (*ComponentEvent) Member ¶
func (e *ComponentEvent) Member() *Member
Member is the guild-scoped identity of the user who used the component, nil in a DM.
func (*ComponentEvent) MessageComponentsWithoutActionRows ¶
func (e *ComponentEvent) MessageComponentsWithoutActionRows() []LayoutComponent
MessageComponentsWithoutActionRows is the message's top-level components with every ActionRow dropped, which is how a handler strips the controls off its own message without rebuilding the text that sits above them.
The components come back opaque. They can be sent again unchanged, but the facade cannot inspect or edit them, because reading a component off Discord is not the same shape as the one that built it.
func (*ComponentEvent) MessageContent ¶
func (e *ComponentEvent) MessageContent() string
MessageContent is the text of the message the component lives on. A handler that only strips the buttons re-sends this so the text survives the update.
func (*ComponentEvent) MessageID ¶
func (e *ComponentEvent) MessageID() string
MessageID is the ID of the message the interacted component is attached to.
func (*ComponentEvent) MessageIsEphemeral ¶
func (e *ComponentEvent) MessageIsEphemeral() bool
MessageIsEphemeral reports whether the message the component lives on is ephemeral. A handler replacing that message has to carry the flag forward, since Discord will not infer it from the original.
func (*ComponentEvent) Respond ¶
func (e *ComponentEvent) Respond(m Message) (err error)
Respond answers with a new message rather than touching the one the component sits on.
func (*ComponentEvent) ShowModal ¶
func (e *ComponentEvent) ShowModal(modal Modal) (err error)
ShowModal answers the interaction by opening a modal form.
func (*ComponentEvent) Token ¶
func (e *ComponentEvent) Token() string
Token returns the interaction's token.
func (*ComponentEvent) Update ¶
func (e *ComponentEvent) Update(m Message) (err error)
Update replaces the message the component sits on.
func (*ComponentEvent) User ¶
func (e *ComponentEvent) User() *User
User is the account that ran the component.
func (*ComponentEvent) UserID ¶
func (e *ComponentEvent) UserID() string
UserID is the ID of the user who used the component.
func (*ComponentEvent) Values ¶
func (e *ComponentEvent) Values() []string
Values are the options chosen from a select menu, empty for buttons.
type Container ¶
type Container struct {
AccentColor int
Components []ContainerSubComponent
}
Container groups components behind an optional colored accent bar. An AccentColor of 0 leaves the bar uncolored.
type ContainerSubComponent ¶
type ContainerSubComponent interface {
// contains filtered or unexported methods
}
ContainerSubComponent is a component that can sit inside a Container.
type Embed ¶
type Embed struct {
Title string
Description string
URL string
Color int
Fields []EmbedField
Author *EmbedAuthor
Thumbnail string
Image string
Timestamp time.Time
}
Embed is a rich embed attached to a Message. Its Type is always "rich" on the wire — no call site in this repo sets anything else.
type EmbedAuthor ¶
EmbedAuthor credits an Embed to a name, optionally linked and iconed.
type EmbedField ¶
EmbedField is one name/value pair inside an Embed.
type EmbedFooter ¶
type EmbedFooter struct {
}
EmbedFooter is the small text shown along the bottom edge of an Embed.
type Emoji ¶
Emoji identifies a Discord emoji shown on a component, such as a Button or a SelectOption.
type EmojiParams ¶
EmojiParams is an emoji upload: a name and a data URI holding the image, e.g. "data:image/png;base64,<encoded>".
type IntOption ¶
type IntOption struct {
Name string
Description string
Required bool
Autocomplete bool
MinValue *int
MaxValue *int
Choices []Choice[int]
}
IntOption is an integer command parameter. MinValue and MaxValue are optional; nil means the limit is left to Discord. Choices and Autocomplete are mutually exclusive, matching Discord's own rule.
type IntegrationType ¶
type IntegrationType int
IntegrationType is the installation scope a command is published under.
const ( IntegrationGuildInstall IntegrationType = iota IntegrationUserInstall )
Integration types a command can be published under.
type InteractionContext ¶
type InteractionContext int
InteractionContext is a place an application command may be invoked from.
const ( ContextGuild InteractionContext = iota ContextBotDM ContextPrivateChannel )
Interaction contexts a command can be made available in.
type InteractionEvent ¶
type InteractionEvent interface {
UserID() string
ChannelID() string
GuildID() string
Member() *Member
User() *User
AvatarURL() string
Client() Client
Respond(m Message) error
Defer(ephemeral bool) error
Followup(m Message) error
FollowupMessage(m Message) (*MessageRef, error)
EditResponse(m Message) error
EditFollowup(messageID string, m Message) error
// MessageID is the message the interaction came from. It is empty for a
// command interaction, which has no source message.
MessageID() string
// MessageContent is the text of the message the interaction came from,
// empty for a command interaction.
MessageContent() string
// FromComponent reports whether the interaction came from a component.
// A component interaction already has a message on screen to edit; a
// command interaction does not, and answers with a followup instead.
FromComponent() bool
}
InteractionEvent is the behavior a CommandEvent and a ComponentEvent share: both can send a followup and both can edit the response already sent. A helper that renders the same view for a slash command and for a button click on that view takes this rather than one concrete event type.
type InteractionKind ¶
type InteractionKind string
InteractionKind names the four kinds of interaction the bot handles.
const ( KindCommand InteractionKind = "command" KindComponent InteractionKind = "component" KindModal InteractionKind = "modal" KindAutocomplete InteractionKind = "autocomplete" )
Interaction kinds.
type InteractionMeta ¶
type InteractionMeta struct {
Kind InteractionKind
Name string
CustomID string
ChannelID string
GuildID string
UserID string
}
InteractionMeta identifies one interaction without exposing the underlying client's types. It is what the unknown-route and panic hooks receive, so callers can log or answer without unwrapping the event.
type InteractiveComponent ¶
type InteractiveComponent interface {
// contains filtered or unexported methods
}
InteractiveComponent is a component that can sit inside an ActionRow, such as a Button or a SelectMenu.
type LayoutComponent ¶
type LayoutComponent interface {
// contains filtered or unexported methods
}
LayoutComponent is a component that can sit at the top level of a message.
type MediaGallery ¶
type MediaGallery struct {
Items []MediaItem
}
MediaGallery displays a grid of images or videos.
type Member ¶
type Member struct {
UserID string
Nick string
Roles []string
// PremiumSince is when the member started boosting the guild (Discord's
// Nitro server boost, unrelated to this bot's contract boosting). It is
// nil for a member who is not boosting.
PremiumSince *time.Time
// User is the account behind the membership. It is nil when Discord sent
// the membership without one.
User *User
// AvatarURL is the member's effective avatar URL within the guild, falling
// back to their account avatar URL if no guild-specific avatar is set.
AvatarURL string
}
Member is a user's guild-scoped identity: their nickname and roles in one specific guild, as opposed to the account-wide fields on User.
type MentionType ¶
type MentionType string
MentionType is a category of mention that can be allowed through in an AllowedMentions.Parse list.
const ( MentionUsers MentionType = "users" MentionRoles MentionType = "roles" MentionEveryone MentionType = "everyone" )
Mention types.
type Message ¶
type Message struct {
Content string
Components []LayoutComponent
Ephemeral bool
Embeds []Embed
Files []File
AllowedMentions *AllowedMentions
SuppressEmbeds bool
// ComponentsV1 keeps the message on Discord's original component model,
// where Content, Embeds and Files coexist with a row of buttons.
// Components v2 forbids that mix and carries all text inside components,
// so a message that needs the old shape must opt out explicitly.
ComponentsV1 bool
// ClearComponents strips every component off the message being edited.
// Editing a message without components leaves the ones already on it in
// place, so a handler that only takes its buttons away has to say so.
// It has no effect on a message being sent.
ClearComponents bool
}
Message is an outgoing message payload.
Content and Components are mutually exclusive: Discord's components v2 messages carry all of their text inside components, so Content is dropped whenever Components is non-empty.
type MessageEditDebouncer ¶
type MessageEditDebouncer struct {
// contains filtered or unexported fields
}
MessageEditDebouncer coalesces and delays rapid consecutive edits to the same message, executing only the latest payload when the debounce window settles.
func NewMessageEditDebouncer ¶
func NewMessageEditDebouncer(window time.Duration, executeFn func(channelID, messageID string, m Message) (*MessageRef, error)) *MessageEditDebouncer
NewMessageEditDebouncer creates a new debouncer with the given window and execution function.
func (*MessageEditDebouncer) Cancel ¶
func (d *MessageEditDebouncer) Cancel(channelID, messageID string)
Cancel removes and stops any pending debounced edit for the given message.
func (*MessageEditDebouncer) Edit ¶
func (d *MessageEditDebouncer) Edit(channelID, messageID string, m Message) (*MessageRef, error)
Edit schedules or updates a debounced message edit for the given channelID and messageID.
func (*MessageEditDebouncer) Flush ¶
func (d *MessageEditDebouncer) Flush()
Flush immediately dispatches all currently pending message edits.
type MessageEvent ¶
type MessageEvent struct {
// contains filtered or unexported fields
}
MessageEvent is one message the bot can see.
func (*MessageEvent) Attachments ¶
func (e *MessageEvent) Attachments() []Attachment
Attachments are the files uploaded with the message.
func (*MessageEvent) AuthorID ¶
func (e *MessageEvent) AuthorID() string
AuthorID is the ID of the account that posted the message.
func (*MessageEvent) AuthorIsBot ¶
func (e *MessageEvent) AuthorIsBot() bool
AuthorIsBot reports whether the message came from a bot, which is how a handler avoids answering itself.
func (*MessageEvent) ChannelID ¶
func (e *MessageEvent) ChannelID() string
ChannelID is the channel the message was posted in.
func (*MessageEvent) Content ¶
func (e *MessageEvent) Content() string
Content is the message's text.
func (*MessageEvent) GuildID ¶
func (e *MessageEvent) GuildID() string
GuildID is the guild the message was posted in, empty in a DM.
func (*MessageEvent) MessageID ¶
func (e *MessageEvent) MessageID() string
MessageID is the message's own ID.
type MessageRef ¶
type MessageRef struct {
ID string
ChannelID string
Content string
Author *User
Timestamp time.Time
}
MessageRef is a Discord message returned by a Client call: the result of sending, editing, or fetching one.
type Modal ¶
Modal is a form Discord presents to the user in response to an interaction, submitted back as a ModalEvent. CustomID follows this bot's "prefix#arg#...#contractHash" convention.
type ModalEvent ¶
type ModalEvent struct {
// contains filtered or unexported fields
}
ModalEvent is one submitted modal form.
func NewModalEventFromPayload ¶
func NewModalEventFromPayload(payload []byte) (*ModalEvent, error)
NewModalEventFromPayload builds a ModalEvent from Discord's own interaction JSON.
func (*ModalEvent) AvatarURL ¶
func (e *ModalEvent) AvatarURL() string
AvatarURL returns the user's effective avatar URL, preferring their guild member avatar when invoked within a guild, and falling back to their account avatar.
func (*ModalEvent) ChannelID ¶
func (e *ModalEvent) ChannelID() string
ChannelID is the channel the modal was opened from.
func (*ModalEvent) Client ¶
func (e *ModalEvent) Client() Client
Client returns the bot's REST client, or nil if none is attached.
func (*ModalEvent) CustomID ¶
func (e *ModalEvent) CustomID() string
CustomID is the modal's identifier, carrying the same routing data as a component's.
func (*ModalEvent) Defer ¶
func (e *ModalEvent) Defer(ephemeral bool) (err error)
Defer acknowledges the submission and promises a new message.
func (*ModalEvent) DeferUpdate ¶
func (e *ModalEvent) DeferUpdate() (err error)
DeferUpdate acknowledges the submission and leaves the message as it is.
func (*ModalEvent) EditFollowup ¶
func (e *ModalEvent) EditFollowup(messageID string, m Message) error
EditFollowup edits a followup message this interaction already sent.
func (*ModalEvent) EditResponse ¶
func (e *ModalEvent) EditResponse(m Message) error
EditResponse replaces the interaction's original response.
func (*ModalEvent) Followup ¶
func (e *ModalEvent) Followup(m Message) error
Followup sends a message after the submission has been deferred or already answered.
func (*ModalEvent) FollowupMessage ¶
func (e *ModalEvent) FollowupMessage(m Message) (*MessageRef, error)
FollowupMessage sends a followup and returns the message it created.
func (*ModalEvent) FromComponent ¶
func (e *ModalEvent) FromComponent() bool
FromComponent reports whether the modal was opened from a component, which is what decides between editing the message and sending a followup.
func (*ModalEvent) GuildID ¶
func (e *ModalEvent) GuildID() string
GuildID is the guild the modal was opened from, empty in a DM.
func (*ModalEvent) Member ¶
func (e *ModalEvent) Member() *Member
Member is the guild-scoped identity of the submitting user, nil in a DM.
func (*ModalEvent) MessageContent ¶
func (e *ModalEvent) MessageContent() string
MessageContent is the text of the message the modal was opened from, empty when the modal came from a command.
func (*ModalEvent) MessageID ¶
func (e *ModalEvent) MessageID() string
MessageID is the message the modal was opened from, empty when the modal came from a command rather than a component.
func (*ModalEvent) Respond ¶
func (e *ModalEvent) Respond(m Message) (err error)
Respond answers the interaction with a new message.
func (*ModalEvent) ShowModal ¶
func (e *ModalEvent) ShowModal(modal Modal) error
ShowModal answers the submission by opening another modal.
func (*ModalEvent) TextValue ¶
func (e *ModalEvent) TextValue(customID string) string
TextValue reads the submitted value of one text input on the modal, identified by its own CustomID. It returns the empty string if no such input is present.
func (*ModalEvent) Update ¶
func (e *ModalEvent) Update(m Message) (err error)
Update replaces the message the modal was opened from.
func (*ModalEvent) User ¶
func (e *ModalEvent) User() *User
User is the account that submitted the modal.
func (*ModalEvent) UserID ¶
func (e *ModalEvent) UserID() string
UserID is the ID of the user who submitted the modal.
type NumberOption ¶
type NumberOption struct {
Name string
Description string
Required bool
MinValue *float64
MaxValue *float64
Choices []Choice[float64]
}
NumberOption is a floating point command parameter. MinValue and MaxValue are optional; nil means the limit is left to Discord.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option is one parameter of a slash command.
type OptionValues ¶
type OptionValues struct {
// contains filtered or unexported fields
}
OptionValues is a snapshot of the options a command was invoked with.
It exists for handlers that have to interrupt themselves and resume on a later interaction — ask for a modal, then finish the original work once the modal comes back. The second interaction carries none of the first one's options, so the handler stashes an OptionValues and reads from it instead.
Names follow the same path-joined convention CommandEvent uses: an option nested under a subcommand is addressed as "group-subcommand-option".
func (OptionValues) Attachment ¶
func (o OptionValues) Attachment(name string) (*Attachment, bool)
Attachment reads an attachment option, resolved against the data Discord sent with the original interaction.
func (OptionValues) Bool ¶
func (o OptionValues) Bool(name string) (bool, bool)
Bool reads a boolean option.
func (OptionValues) Float ¶
func (o OptionValues) Float(name string) (float64, bool)
Float reads a number option.
func (OptionValues) Int ¶
func (o OptionValues) Int(name string) (int, bool)
Int reads an integer option.
func (OptionValues) String ¶
func (o OptionValues) String(name string) (string, bool)
String reads a string option.
func (OptionValues) Subcommand ¶
func (o OptionValues) Subcommand() (string, bool)
Subcommand is the name of the subcommand that was invoked, if any.
func (OptionValues) SubcommandPath ¶
func (o OptionValues) SubcommandPath() []string
SubcommandPath is the full subcommand path, outermost first.
type Permissions ¶
type Permissions int64
Permissions is a Discord permission bitmask for a user in a channel, as returned by Client.UserChannelPermissions.
func (Permissions) Administrator ¶
func (p Permissions) Administrator() bool
Administrator reports whether the permission set includes Administrator.
func (Permissions) CreatePublicThreads ¶
func (p Permissions) CreatePublicThreads() bool
CreatePublicThreads reports whether the permission set includes Create Public Threads.
func (Permissions) SendMessages ¶
func (p Permissions) SendMessages() bool
SendMessages reports whether the permission set includes Send Messages.
type ReactionEvent ¶
type ReactionEvent struct {
// contains filtered or unexported fields
}
ReactionEvent is one reaction added to or removed from a message.
func (*ReactionEvent) ChannelID ¶
func (e *ReactionEvent) ChannelID() string
ChannelID is the channel the reacted-to message is in.
func (*ReactionEvent) EmojiID ¶
func (e *ReactionEvent) EmojiID() string
EmojiID is the snowflake of a custom emoji, empty for a unicode one.
func (*ReactionEvent) EmojiName ¶
func (e *ReactionEvent) EmojiName() string
EmojiName is the emoji's name: the character itself for a unicode emoji, the bare name for a custom one.
func (*ReactionEvent) EmojiRef ¶
func (e *ReactionEvent) EmojiRef() string
EmojiRef identifies the emoji the way the REST API wants it: "name:id" for a custom emoji, the bare name for a unicode one. Client.RemoveMessageReaction takes this form.
func (*ReactionEvent) GuildID ¶
func (e *ReactionEvent) GuildID() string
GuildID is the guild the reaction happened in, empty in a DM.
func (*ReactionEvent) MessageID ¶
func (e *ReactionEvent) MessageID() string
MessageID is the message the reaction is on.
func (*ReactionEvent) UserID ¶
func (e *ReactionEvent) UserID() string
UserID is the user who reacted.
type Role ¶
type Role struct {
ID string
Name string
Color int
Position int
Managed bool
Mentionable bool
Hoist bool
}
Role is a guild role.
type RoleOption ¶
RoleOption is a command parameter that resolves to a role.
type RoleParams ¶
RoleParams is the set of fields used to create or edit a guild role. A nil Mentionable leaves the role's current mentionable setting unchanged.
type Section ¶
type Section struct {
Components []TextDisplay
Accessory SectionAccessory
}
Section pairs up to three TextDisplay components with an accessory shown beside them — a Thumbnail image or a Button.
type SectionAccessory ¶
type SectionAccessory interface {
// contains filtered or unexported methods
}
SectionAccessory is a component that can appear beside a Section's text — either a Thumbnail image or a Button.
type SelectMenu ¶
type SelectMenu struct {
CustomID string
Placeholder string
MinValues *int
MaxValues int
Disabled bool
Options []SelectOption
}
SelectMenu is a dropdown component that lives inside an ActionRow.
MinValues is a pointer because Discord distinguishes "unset", which it defaults to 1, from an explicit 0, which is how a menu is made fully deselectable. A plain int cannot express that difference.
type SelectOption ¶
SelectOption is one choice in a SelectMenu.
type Separator ¶
type Separator struct {
Divider bool
Spacing SeparatorSpacing
}
Separator is a visual divider between components.
type SeparatorSpacing ¶
type SeparatorSpacing int
SeparatorSpacing sizes the gap a Separator leaves around itself.
const ( SeparatorSpacingSmall SeparatorSpacing = iota SeparatorSpacingLarge )
Separator spacing sizes.
type StringOption ¶
type StringOption struct {
Name string
Description string
Required bool
Autocomplete bool
Choices []Choice[string]
MinLength *int
MaxLength *int
}
StringOption is a string command parameter. MinLength and MaxLength are optional; nil means the limit is left to Discord. Choices and Autocomplete are mutually exclusive, matching Discord's own rule.
type SubCommand ¶
SubCommand is a named grouping of options nested one level under a Command or a SubCommandGroup.
type SubCommandGroup ¶
type SubCommandGroup struct {
Name string
Description string
Options []SubCommand
}
SubCommandGroup nests SubCommands one level under a Command. Discord does not allow a group to contain another group, so Options is typed as []SubCommand rather than []Option: illegal nesting is a compile error instead of a runtime rejection.
type TextDisplay ¶
type TextDisplay struct {
Content string
}
TextDisplay renders markdown text as a components v2 element.
type TextInput ¶
type TextInput struct {
CustomID string
Label string
Style TextInputStyle
Placeholder string
Value string
Required bool
MinLength int
MaxLength int
}
TextInput is one text field on a Modal.
type TextInputStyle ¶
type TextInputStyle int
TextInputStyle is the shape of a modal text input: a single line or a multi-line paragraph box.
const ( TextInputStyleShort TextInputStyle = iota TextInputStyleParagraph )
Text input styles a modal's TextInput can take.
type ThreadMember ¶
ThreadMember is a member of a Discord thread.
type UnknownEvent ¶
type UnknownEvent struct {
// contains filtered or unexported fields
}
UnknownEvent is an interaction that matched no registered route: a button on a message older than the handler that made it, a command the bot no longer publishes. It carries enough to answer the user so the interaction does not hang with "this application did not respond".
It holds the two ways to answer as closures rather than holding the interaction itself, because the four interaction kinds are four unrelated types and only one of them answers with choices.
func (*UnknownEvent) Meta ¶
func (e *UnknownEvent) Meta() InteractionMeta
Meta identifies the interaction that went unrouted.
func (*UnknownEvent) Respond ¶
func (e *UnknownEvent) Respond(m Message) error
Respond answers with a message. Discord rejects this for an autocomplete interaction, which has no message response; use RespondChoices there.
func (*UnknownEvent) RespondChoices ¶
func (e *UnknownEvent) RespondChoices(choices []Choice[string]) error
RespondChoices answers an unrouted autocomplete, which only accepts a choice list. An empty list is the way to say "no suggestions".
type User ¶
type User struct {
ID string
Username string
GlobalName string
Bot bool
// Discriminator is the four-digit tag from the legacy username system,
// and "0" for an account migrated to the new one.
Discriminator string
// AvatarURL is the user's account avatar URL.
AvatarURL string
}
User is a Discord account.
type UserOption ¶
UserOption is a command parameter that resolves to a guild member or user.