Documentation
¶
Overview ¶
Package gumi declares a Discord command once and runs it both as a slash (or context menu) command and as a classic prefixed message command. Handlers read ctx.Options and never care how they were invoked.
Index ¶
- Variables
- func ComponentID(cmd *Command, args ...string) string
- func DefaultErrorHandler(ctx *Context, err error)
- func UserMessageOf(err error) (string, bool)
- type AutocompleteContext
- type AutocompleteErrorHandler
- type AutocompleteHandler
- type Check
- type CheckError
- type Choice
- type Command
- func (c *Command) IsGroup() bool
- func (c *Command) Parent() *Command
- func (c *Command) Path() []string
- func (c *Command) QualifiedName() string
- func (c *Command) Root() *Command
- func (c *Command) Subcommand(name string) *Command
- func (c *Command) Usage(lead string) string
- func (c *Command) Walk(fn func(*Command))
- type CommandType
- type ComponentContext
- func (c *ComponentContext) Arg(i int) string
- func (c *ComponentContext) ChannelID() string
- func (c *ComponentContext) GuildID() string
- func (c *ComponentContext) IsModal() bool
- func (c *ComponentContext) Modal(customID, title string, inputs ...discordgo.TextInput) error
- func (c *ComponentContext) Permissions() int64
- func (c *ComponentContext) Reply(r *Response) error
- func (c *ComponentContext) ResolvedChannels() map[string]*discordgo.Channel
- func (c *ComponentContext) TextInput(customID string) string
- func (c *ComponentContext) Update(r *Response) error
- func (c *ComponentContext) UserID() string
- func (c *ComponentContext) Values() []string
- type ComponentHandler
- type Config
- type Context
- func (c *Context) Author() *discordgo.User
- func (c *Context) AuthorID() string
- func (c *Context) BotPermissions() (int64, error)
- func (c *Context) Channel() (*discordgo.Channel, error)
- func (c *Context) ChannelID() string
- func (c *Context) Context() context.Context
- func (c *Context) Defer() error
- func (c *Context) Delete() error
- func (c *Context) DisplayPrefix() string
- func (c *Context) Edit(r *Response) error
- func (c *Context) Followup(r *Response) (*discordgo.Message, error)
- func (c *Context) Get(key string) (any, bool)
- func (c *Context) Guild() (*discordgo.Guild, error)
- func (c *Context) GuildID() string
- func (c *Context) IsInteraction() bool
- func (c *Context) IsMessage() bool
- func (c *Context) Locale() discordgo.Locale
- func (c *Context) Member() *discordgo.Member
- func (c *Context) OriginalResponse() (*discordgo.Message, error)
- func (c *Context) Permissions() (int64, error)
- func (c *Context) Reply(r *Response) error
- func (c *Context) ReplyEmbed(embed *discordgo.MessageEmbed) error
- func (c *Context) ReplyEphemeral(content string) error
- func (c *Context) ReplyText(content string) error
- func (c *Context) Replyf(format string, args ...any) error
- func (c *Context) Responded() bool
- func (c *Context) Set(key string, value any)
- func (c *Context) SetContext(ctx context.Context)
- func (c *Context) SetEphemeral(on bool)
- type Cooldown
- type CooldownError
- type CooldownScope
- type ErrorHandler
- type FallbackHandler
- type Handler
- type HelpConfig
- type Middleware
- type Option
- func Attachment(name, description string) *Option
- func Boolean(name, description string) *Option
- func Channel(name, description string) *Option
- func Integer(name, description string) *Option
- func Mentionable(name, description string) *Option
- func Number(name, description string) *Option
- func Role(name, description string) *Option
- func String(name, description string) *Option
- func User(name, description string) *Option
- func (o *Option) Greedy() *Option
- func (o *Option) Require() *Option
- func (o *Option) SlashOnly() *Option
- func (o *Option) WithAutocomplete(h AutocompleteHandler) *Option
- func (o *Option) WithChannelTypes(types ...discordgo.ChannelType) *Option
- func (o *Option) WithChoices(choices ...Choice) *Option
- func (o *Option) WithLength(minLength, maxLength int) *Option
- func (o *Option) WithRange(minValue, maxValue float64) *Option
- type OptionError
- type OptionType
- type Options
- func (o *Options) Attachment(name string) *discordgo.MessageAttachment
- func (o *Options) Bool(name string) bool
- func (o *Options) BoolOr(name string, def bool) bool
- func (o *Options) Channel(name string) *discordgo.Channel
- func (o *Options) Float(name string) float64
- func (o *Options) Get(name string) *Value
- func (o *Options) Has(name string) bool
- func (o *Options) ID(name string) string
- func (o *Options) Int(name string) int64
- func (o *Options) IntOr(name string, def int64) int64
- func (o *Options) Len() int
- func (o *Options) Member(name string) *discordgo.Member
- func (o *Options) Role(name string) *discordgo.Role
- func (o *Options) String(name string) string
- func (o *Options) StringOr(name, def string) string
- func (o *Options) User(name string) *discordgo.User
- type PanicError
- type PrefixResolver
- type Response
- type Router
- func (r *Router) AddCheck(checks ...Check)
- func (r *Router) ApplicationCommands() (global []*discordgo.ApplicationCommand, ...)
- func (r *Router) Bind(s *discordgo.Session) func()
- func (r *Router) ClearCommands(s *discordgo.Session, guildID string) error
- func (r *Router) Commands() []*Command
- func (r *Router) Config() Config
- func (r *Router) HandleInteraction(s *discordgo.Session, i *discordgo.InteractionCreate)
- func (r *Router) HandleMessage(s *discordgo.Session, m *discordgo.MessageCreate)
- func (r *Router) IsOwner(userID string) bool
- func (r *Router) Lookup(path ...string) *Command
- func (r *Router) Mention(c *Command) string
- func (r *Router) MustRegister(cmds ...*Command)
- func (r *Router) Prefixes(s *discordgo.Session, guildID, channelID string) []string
- func (r *Router) Register(cmds ...*Command) error
- func (r *Router) Sync(s *discordgo.Session) error
- func (r *Router) Use(mw ...Middleware)
- type Source
- type SubcommandError
- type UserError
- type UserFacing
- type Value
- func (v *Value) Attachment() *discordgo.MessageAttachment
- func (v *Value) Bool() bool
- func (v *Value) Channel() (*discordgo.Channel, error)
- func (v *Value) Float() float64
- func (v *Value) ID() string
- func (v *Value) Int() int64
- func (v *Value) IsRole() bool
- func (v *Value) IsUser() bool
- func (v *Value) Member() (*discordgo.Member, error)
- func (v *Value) Raw() string
- func (v *Value) Role() (*discordgo.Role, error)
- func (v *Value) String() string
- func (v *Value) User() (*discordgo.User, error)
Constants ¶
This section is empty.
Variables ¶
var ( ErrMissingOption = errors.New("missing required option") ErrMissingSubcommand = errors.New("missing subcommand") ErrUnknownSubcommand = errors.New("unknown subcommand") ErrNoHandler = errors.New("command has no handler") ErrNoResponse = errors.New("no response has been sent yet") ErrAlreadyResponded = errors.New("interaction already responded to") ErrMissingTarget = errors.New("missing command target") )
Sentinel errors returned by the router.
Functions ¶
func ComponentID ¶ added in v1.0.0
ComponentID builds a custom ID that routes back to cmd's Components handler with args. It returns "" when the ID would exceed Discord's 100-character limit; args must not contain ':'.
func DefaultErrorHandler ¶ added in v1.0.0
DefaultErrorHandler replies with the user-facing message, if any, and a generic one otherwise. Silent check failures get no reply.
func UserMessageOf ¶ added in v1.0.0
Types ¶
type AutocompleteContext ¶ added in v1.0.0
type AutocompleteContext struct {
Session *discordgo.Session
Router *Router
Command *Command
Interaction *discordgo.InteractionCreate
// Option is the declaration of the focused option.
Option *Option
// Value is what has been typed into the focused option so far.
Value string
// Options holds every option filled in so far, the focused one included.
Options *Options
// contains filtered or unexported fields
}
AutocompleteContext is one keystroke's worth of an option being typed.
func (*AutocompleteContext) ChannelID ¶ added in v1.0.0
func (c *AutocompleteContext) ChannelID() string
func (*AutocompleteContext) Context ¶ added in v1.0.0
func (c *AutocompleteContext) Context() context.Context
Context expires shortly before Discord stops waiting for suggestions.
func (*AutocompleteContext) GuildID ¶ added in v1.0.0
func (c *AutocompleteContext) GuildID() string
func (*AutocompleteContext) Locale ¶ added in v1.0.0
func (c *AutocompleteContext) Locale() discordgo.Locale
func (*AutocompleteContext) UserID ¶ added in v1.0.0
func (c *AutocompleteContext) UserID() string
UserID returns the ID of the user who is typing.
type AutocompleteErrorHandler ¶ added in v1.0.0
type AutocompleteErrorHandler func(ctx *AutocompleteContext, err error)
AutocompleteErrorHandler receives errors and recovered panics from autocomplete handlers. The user just sees no suggestions.
type AutocompleteHandler ¶ added in v1.0.0
type AutocompleteHandler func(ctx *AutocompleteContext) ([]Choice, error)
AutocompleteHandler suggests values for the option being typed. At most 25 choices are shown; names over 100 characters are trimmed and string values over 100 characters dropped.
type Check ¶ added in v1.0.0
Check gates a command: it runs after middleware, before cooldowns. Reject with a UserFacing error to tell the user why.
var DMOnly Check = func(ctx *Context) error { if ctx.GuildID() != "" { return &CheckError{Check: "dm_only", Message: "This command can only be used in DMs."} } return nil }
DMOnly rejects invocations inside guilds.
var GuildOnly Check = func(ctx *Context) error { if ctx.GuildID() == "" { return &CheckError{Check: "guild_only", Message: "This command can only be used in a server."} } return nil }
GuildOnly rejects invocations outside of guilds.
var NSFW Check = func(ctx *Context) error { if ctx.GuildID() == "" { return nil } ch, err := ctx.Channel() if err != nil { return err } if ch.IsThread() && ch.ParentID != "" { if ch, err = ctx.channel(ch.ParentID); err != nil { return err } } if !ch.NSFW { return &CheckError{Check: "nsfw", Message: "This command can only be used in NSFW channels."} } return nil }
NSFW rejects invocations in non-NSFW guild channels. DMs are allowed. Threads inherit the flag from their parent channel.
var OwnerOnly Check = func(ctx *Context) error { if !ctx.Router.IsOwner(ctx.AuthorID()) { return &CheckError{Check: "owner_only", Message: "This command is restricted to the bot owner.", Silent: true} } return nil }
OwnerOnly silently rejects everyone except Config.OwnerIDs.
func Any ¶ added in v1.0.0
Any passes if at least one of the checks passes. If all fail, the error of the last check is returned.
func BotHasPermissions ¶ added in v1.0.0
BotHasPermissions needs all the given channel permissions for the bot. Outside guilds it passes.
func HasPermissions ¶ added in v1.0.0
HasPermissions needs all the given channel permissions (admins pass). Outside guilds it passes.
type CheckError ¶ added in v1.0.0
type CheckError struct {
Check string
Message string
// Silent sends no reply, for commands whose existence shouldn't be
// revealed.
Silent bool
}
func (*CheckError) Error ¶ added in v1.0.0
func (e *CheckError) Error() string
func (*CheckError) UserMessage ¶ added in v1.0.0
func (e *CheckError) UserMessage() string
type Command ¶
type Command struct {
// Chat input names: 1-32 lowercase chars, no spaces. Context menu
// names are free-form.
Name string
// Shown in Discord and in help (1-100 chars). Discord ignores it for
// context menu commands.
Description string
// Defaults to ChatInput.
Type CommandType
Category string
// Extra prefix names; slash ignores them.
Aliases []string
// Parsed positionally in declaration order over prefix.
Options []*Option
// Subcommands turn this into a group: no options or handler allowed,
// at most two levels deep (command > group > sub).
Subcommands []*Command
// Default is the subcommand a prefix invocation runs when no
// subcommand is given, e.g. "bt!groups" runs "bt!groups list". If the
// next word isn't a subcommand, it's passed to the default as an
// argument: "bt!bookmarks popularity" runs "bt!bookmarks list popularity".
Default string
// Required for non-group commands.
Handler Handler
// Group checks also guard its subcommands.
Checks []Check
Middleware []Middleware
// Set on a group to cover its subcommands too.
Cooldown *Cooldown
// Acknowledge first ("thinking…", or typing over prefix), giving the
// handler up to 15 minutes.
Defer bool
// Invoker-only replies. No effect over prefix.
Ephemeral bool
// Age-restricts the slash command. This alone changes nothing at runtime;
// add NSFW to Checks to gate prefix invocations too.
NSFW bool
// Hides the slash command by default (admins can override). Also not a
// runtime check; use HasPermissions for that.
DefaultMemberPermissions *int64
// Where the slash command shows up; empty means Discord's default.
Contexts []discordgo.InteractionContextType
IntegrationTypes []discordgo.ApplicationIntegrationType
// Register the slash command only here instead of globally.
GuildIDs []string
DisableSlash bool
DisablePrefix bool
Hidden bool
// Shown in help; write without prefix, e.g. "set prefix !".
Examples []string
// Components handles interactions on components built with
// ComponentID. Only root commands receive them.
Components ComponentHandler
// contains filtered or unexported fields
}
Command is declared once and works as both a slash command and a prefix command.
func HelpCommand ¶ added in v1.0.0
func HelpCommand(cfg HelpConfig) *Command
HelpCommand documents every command on the router it runs in:
/help – overview with a category menu /help set prefix – details, usage, options, cooldown
The menus are stateless: each custom ID carries the invoker, the syntax mode and the target, so they keep working across restarts.
func (*Command) QualifiedName ¶ added in v1.0.0
func (*Command) Subcommand ¶ added in v1.0.0
Subcommand finds a direct subcommand by name or alias, ignoring case.
type CommandType ¶ added in v1.0.0
type CommandType int
CommandType mirrors Discord application command types.
const ( ChatInput CommandType = iota // MessageContext runs on a message: right-click it, or reply to it // (or pass a link / ID) over prefix. MessageContext // UserContext runs on a user: right-click them, or pass a mention / ID // over prefix (defaults to the author). UserContext )
func (CommandType) String ¶ added in v1.0.0
func (t CommandType) String() string
type ComponentContext ¶ added in v1.0.0
type ComponentContext struct {
Session *discordgo.Session
Router *Router
Command *Command
Interaction *discordgo.InteractionCreate
// Args are the custom ID's parts after the command name.
Args []string
// contains filtered or unexported fields
}
ComponentContext is a button click, select or modal submit.
func (*ComponentContext) Arg ¶ added in v1.0.0
func (c *ComponentContext) Arg(i int) string
Arg returns the i-th arg, or "" when absent.
func (*ComponentContext) ChannelID ¶ added in v1.0.0
func (c *ComponentContext) ChannelID() string
func (*ComponentContext) GuildID ¶ added in v1.0.0
func (c *ComponentContext) GuildID() string
func (*ComponentContext) IsModal ¶ added in v1.0.0
func (c *ComponentContext) IsModal() bool
IsModal reports whether this is a modal submit.
func (*ComponentContext) Modal ¶ added in v1.0.0
func (c *ComponentContext) Modal(customID, title string, inputs ...discordgo.TextInput) error
Modal opens a modal whose submit routes back with the given custom ID.
func (*ComponentContext) Permissions ¶ added in v1.0.0
func (c *ComponentContext) Permissions() int64
Permissions are the user's channel permissions (all of them in DMs).
func (*ComponentContext) Reply ¶ added in v1.0.0
func (c *ComponentContext) Reply(r *Response) error
Reply sends a new message; set Ephemeral for an invoker-only one.
func (*ComponentContext) ResolvedChannels ¶ added in v1.0.0
func (c *ComponentContext) ResolvedChannels() map[string]*discordgo.Channel
ResolvedChannels are the channels picked in a channel select, by ID.
func (*ComponentContext) TextInput ¶ added in v1.0.0
func (c *ComponentContext) TextInput(customID string) string
TextInput is a modal text input's submitted value, or "".
func (*ComponentContext) Update ¶ added in v1.0.0
func (c *ComponentContext) Update(r *Response) error
Update edits the message the component is on.
func (*ComponentContext) UserID ¶ added in v1.0.0
func (c *ComponentContext) UserID() string
UserID returns the ID of the user who clicked.
func (*ComponentContext) Values ¶ added in v1.0.0
func (c *ComponentContext) Values() []string
Values are a select menu's chosen values.
type ComponentHandler ¶ added in v1.0.0
type ComponentHandler func(ctx *ComponentContext) error
ComponentHandler handles clicks, selects and modal submits on components whose custom IDs came from ComponentID.
type Config ¶ added in v1.0.0
type Config struct {
// Prefixes accepted everywhere. Ignored if PrefixResolver is set.
Prefixes []string
// PrefixResolver returns per-guild prefixes.
PrefixResolver PrefixResolver
// DisableMentionPrefix turns off "@Bot command" invocation.
DisableMentionPrefix bool
// DisablePrefixCommands turns off prefix invocation entirely.
DisablePrefixCommands bool
// DisableSlashCommands turns off interaction handling and Sync.
DisableSlashCommands bool
// DevGuildID registers every slash command to this guild instead of
// globally (instant propagation, useful for development).
DevGuildID string
// ApplicationID used for Sync. Fetched from the API if empty.
ApplicationID string
OwnerIDs []string
// ErrorHandler replaces the default error handler.
ErrorHandler ErrorHandler
// AutocompleteErrorHandler receives autocomplete handler errors, which
// are otherwise dropped.
AutocompleteErrorHandler AutocompleteErrorHandler
// Fallback is called for messages that were not commands.
Fallback FallbackHandler
// AllowedMentions applied to prefix replies that don't set their own.
AllowedMentions *discordgo.MessageAllowedMentions
// DisableReplyReference stops prefix replies from quoting the invoking
// message.
DisableReplyReference bool
// BaseContext produces the root context.Context for each invocation.
BaseContext func() context.Context
}
type Context ¶ added in v1.0.0
type Context struct {
Session *discordgo.Session
Router *Router
Command *Command
Source Source
Prefix string
Message *discordgo.Message
Interaction *discordgo.InteractionCreate
Options *Options
TargetMessage *discordgo.Message
TargetUser *discordgo.User
// Guilds only; nil in DMs.
TargetMember *discordgo.Member
StartedAt time.Time
// contains filtered or unexported fields
}
Context is a single command invocation. Replies work the same whether it came from a slash command or a message. Exactly one of Message and Interaction is set.
func (*Context) BotPermissions ¶ added in v1.0.0
func (*Context) Channel ¶ added in v1.0.0
Channel fetches the invoking channel (state cache first, then REST).
func (*Context) Context ¶ added in v1.0.0
Context carries cancellation and deadlines; see middleware.Timeout.
func (*Context) Defer ¶ added in v1.0.0
Defer gives the handler up to 15 minutes by showing "thinking…" (or typing, over prefix). Calling it twice does nothing.
func (*Context) Delete ¶ added in v1.0.0
Delete removes the original response (interactions) or the last reply.
func (*Context) DisplayPrefix ¶ added in v1.0.0
DisplayPrefix is the used prefix, falling back to the guild's first one.
func (*Context) Edit ¶ added in v1.0.0
Edit rewrites the original response, or the last reply over prefix. Replies instead if nothing was sent yet.
func (*Context) Followup ¶ added in v1.0.0
Followup sends an extra message, responding first if it has to.
func (*Context) Guild ¶ added in v1.0.0
Guild fetches the invoking guild (state cache first, then REST).
func (*Context) IsInteraction ¶ added in v1.0.0
func (*Context) OriginalResponse ¶ added in v1.0.0
func (*Context) Permissions ¶ added in v1.0.0
Permissions are the invoker's channel permissions (all of them outside guilds).
func (*Context) Reply ¶ added in v1.0.0
Reply answers once over interactions (editing the deferred placeholder if there is one, else following up), or replies to the message.
func (*Context) ReplyEmbed ¶ added in v1.0.0
func (c *Context) ReplyEmbed(embed *discordgo.MessageEmbed) error
func (*Context) ReplyEphemeral ¶ added in v1.0.0
func (*Context) Responded ¶ added in v1.0.0
Responded reports whether an initial response (or Defer) has been sent.
func (*Context) SetContext ¶ added in v1.0.0
func (*Context) SetEphemeral ¶ added in v1.0.0
SetEphemeral decides at runtime whether replies are invoker-only, e.g. from an option. Discord fixes it with the first response (including Defer), so call it before that. No effect over prefix.
type Cooldown ¶ added in v1.0.0
type Cooldown struct {
Scope CooldownScope
Uses int
Per time.Duration
// contains filtered or unexported fields
}
Cooldown is a fixed-window rate limiter: Uses invocations per Per for every key in Scope (Uses defaults to 1). Safe for concurrent use. Set it on a group to cover its subcommands:
Cooldown: &gumi.Cooldown{Uses: 2, Per: 10 * time.Second}
func NewCooldown ¶ added in v1.0.0
func NewCooldown(scope CooldownScope, uses int, per time.Duration) *Cooldown
type CooldownError ¶ added in v1.0.0
type CooldownError struct {
Remaining time.Duration
Scope CooldownScope
}
func (*CooldownError) Error ¶ added in v1.0.0
func (e *CooldownError) Error() string
func (*CooldownError) UserMessage ¶ added in v1.0.0
func (e *CooldownError) UserMessage() string
type CooldownScope ¶ added in v1.0.0
type CooldownScope int
CooldownScope determines which key a cooldown bucket is tied to.
const ( // CooldownUser limits each user independently (default). CooldownUser CooldownScope = iota // CooldownChannel limits each channel independently. CooldownChannel // CooldownGuild limits each guild independently (DMs are keyed by channel). CooldownGuild // CooldownGlobal limits the command for everyone. CooldownGlobal )
func (CooldownScope) String ¶ added in v1.0.0
func (s CooldownScope) String() string
type ErrorHandler ¶
ErrorHandler receives every error returned from the command pipeline.
type FallbackHandler ¶ added in v1.0.0
type FallbackHandler func(s *discordgo.Session, m *discordgo.MessageCreate)
FallbackHandler receives messages (from non-bot users) that were not dispatched as a command.
type HelpConfig ¶ added in v1.0.0
type HelpConfig struct {
// Name of the command (default "help").
Name string
// Description (default "Shows the list of commands or details about one").
Description string
// Category the help command itself is listed under (default "General").
Category string
// Aliases for prefix invocation.
Aliases []string
// Title of the overview embed (default "Commands").
Title string
// Color of the embeds.
Color int
Footer string
// ShowHidden lists hidden commands too.
ShowHidden bool
// Public makes help replies visible to everyone (default: ephemeral).
Public bool
// Uncategorized is the category name for commands without one (default "Other").
Uncategorized string
// CategoryOrder lists categories first, in this order; the rest follow
// alphabetically.
CategoryOrder []string
}
HelpConfig customises the built-in help command.
type Middleware ¶ added in v1.0.0
Middleware wraps a Handler. Router middleware runs first, then the command chain's, outermost first.
type Option ¶
type Option struct {
Type OptionType
Name string
Description string
Required bool
Choices []Choice
// ChannelTypes restricts channel options to the given types.
ChannelTypes []discordgo.ChannelType
// MinValue / MaxValue apply to integer and number options.
MinValue *float64
MaxValue *float64
// MinLength / MaxLength apply to string options.
MinLength *int
MaxLength *int
// Consume the rest of the message over prefix (string only). Only
// attachments and slash-only options may follow it. Ignored by slash
// commands.
Rest bool
// Skip the option over prefix, where it keeps its zero value. Lets a
// slash command take extra options without breaking the positional
// prefix syntax. Cannot be required.
NoPrefix bool
// Autocomplete suggests values while the user types (string, integer
// and number options only; not with Choices). Ignored by prefix
// commands.
Autocomplete AutocompleteHandler
}
Option is one command argument; the same declaration feeds the slash definition and the prefix parser.
func Attachment ¶ added in v1.0.0
func Mentionable ¶ added in v1.0.0
func (*Option) WithAutocomplete ¶ added in v1.0.0
func (o *Option) WithAutocomplete(h AutocompleteHandler) *Option
func (*Option) WithChannelTypes ¶ added in v1.0.0
func (o *Option) WithChannelTypes(types ...discordgo.ChannelType) *Option
func (*Option) WithChoices ¶ added in v1.0.0
func (*Option) WithLength ¶ added in v1.0.0
type OptionError ¶ added in v1.0.0
func (*OptionError) Error ¶ added in v1.0.0
func (e *OptionError) Error() string
func (*OptionError) Unwrap ¶ added in v1.0.0
func (e *OptionError) Unwrap() error
func (*OptionError) UserMessage ¶ added in v1.0.0
func (e *OptionError) UserMessage() string
type OptionType ¶ added in v1.0.0
type OptionType = discordgo.ApplicationCommandOptionType
const ( OptionString OptionType = discordgo.ApplicationCommandOptionString OptionInteger OptionType = discordgo.ApplicationCommandOptionInteger OptionBoolean OptionType = discordgo.ApplicationCommandOptionBoolean OptionUser OptionType = discordgo.ApplicationCommandOptionUser OptionChannel OptionType = discordgo.ApplicationCommandOptionChannel OptionRole OptionType = discordgo.ApplicationCommandOptionRole OptionMentionable OptionType = discordgo.ApplicationCommandOptionMentionable OptionNumber OptionType = discordgo.ApplicationCommandOptionNumber OptionAttachment OptionType = discordgo.ApplicationCommandOptionAttachment )
Subcommand types are deliberately absent: use Command.Subcommands.
type Options ¶ added in v1.0.0
type Options struct {
// contains filtered or unexported fields
}
func (*Options) Attachment ¶ added in v1.0.0
func (o *Options) Attachment(name string) *discordgo.MessageAttachment
type PanicError ¶ added in v1.0.0
func (*PanicError) Error ¶ added in v1.0.0
func (e *PanicError) Error() string
type PrefixResolver ¶
PrefixResolver returns the prefixes accepted in the given guild/channel.
type Response ¶ added in v1.0.0
type Response struct {
Content string
Embeds []*discordgo.MessageEmbed
Components []discordgo.MessageComponent
Files []*discordgo.File
AllowedMentions *discordgo.MessageAllowedMentions
// Invoker-only for interactions; ignored over prefix.
Ephemeral bool
TTS bool
Flags discordgo.MessageFlags
}
func Embed ¶ added in v1.0.0
func Embed(embed *discordgo.MessageEmbed) *Response
type Router ¶ added in v0.3.0
type Router struct {
// contains filtered or unexported fields
}
func (*Router) AddCheck ¶ added in v1.0.0
AddCheck appends router-wide checks that run before every command.
func (*Router) ApplicationCommands ¶ added in v1.0.0
func (r *Router) ApplicationCommands() (global []*discordgo.ApplicationCommand, byGuild map[string][]*discordgo.ApplicationCommand)
ApplicationCommands builds the Discord definitions, split into global and per-guild commands. DevGuildID is not applied here; see Sync.
func (*Router) Bind ¶ added in v1.0.0
Bind hooks the router into the session; the result unbinds it.
func (*Router) ClearCommands ¶ added in v1.0.0
ClearCommands wipes global (guildID == "") or guild commands.
func (*Router) HandleInteraction ¶ added in v1.0.0
func (r *Router) HandleInteraction(s *discordgo.Session, i *discordgo.InteractionCreate)
HandleInteraction runs application commands, their autocomplete, and the components and modals built with ComponentID. It ignores everything else, so it can share a session with your own component and modal handlers.
func (*Router) HandleMessage ¶ added in v1.0.0
func (r *Router) HandleMessage(s *discordgo.Session, m *discordgo.MessageCreate)
func (*Router) Lookup ¶ added in v1.0.0
Lookup resolves a command by prefix path, e.g. Lookup("set", "prefix"). Names and aliases both match; nil if not found.
func (*Router) Mention ¶ added in v1.0.0
Mention renders a chat command as a clickable </name:id> mention, or "" before Sync or for commands Discord cannot mention.
func (*Router) MustRegister ¶ added in v1.0.0
MustRegister is Register but panics on error.
func (*Router) Register ¶ added in v1.0.0
Register validates and adds top-level commands. Either all commands are registered or none.
func (*Router) Sync ¶ added in v1.0.0
Sync bulk-overwrites the application commands. With DevGuildID set, everything lands in that guild instead (globals are left alone). Call it after the session is open.
func (*Router) Use ¶ added in v1.0.0
func (r *Router) Use(mw ...Middleware)
Use appends router-wide middleware. Middleware runs in registration order.
type SubcommandError ¶ added in v1.0.0
func (*SubcommandError) Error ¶ added in v1.0.0
func (e *SubcommandError) Error() string
func (*SubcommandError) Unwrap ¶ added in v1.0.0
func (e *SubcommandError) Unwrap() error
Unwrap matches ErrUnknownSubcommand or ErrMissingSubcommand.
func (*SubcommandError) UserMessage ¶ added in v1.0.0
func (e *SubcommandError) UserMessage() string
type UserError ¶ added in v1.0.0
UserError is for when the user did something wrong (bad input, nothing found).
func NewUserError ¶ added in v1.0.0
func WrapUserError ¶ added in v1.0.0
func (*UserError) UserMessage ¶ added in v1.0.0
type UserFacing ¶ added in v1.0.0
UserFacing errors are safe to show the invoker; anything else gets a generic "something went wrong" reply.
type Value ¶ added in v1.0.0
type Value struct {
Type OptionType
// contains filtered or unexported fields
}
Value is one parsed argument. Entities resolve lazily (state cache, then REST) for prefix invocations; slash uses Discord's resolved data.
func (*Value) Attachment ¶ added in v1.0.0
func (v *Value) Attachment() *discordgo.MessageAttachment
func (*Value) Raw ¶ added in v1.0.0
Raw is the value as typed over prefix, or its string form from slash.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package middleware provides common middleware for gumi.Router.
|
Package middleware provides common middleware for gumi.Router. |