Documentation
¶
Index ¶
- Variables
- func DefaultErrorHandler(s *discordgo.Session, i *discordgo.InteractionCreate, err error)
- func DefaultRecoverHandler(s *discordgo.Session, i *discordgo.InteractionCreate, recovered any, ...)
- func Defer(s *discordgo.Session, i *discordgo.InteractionCreate, ephemeral bool) error
- func RespondEmptyAutocomplete(s *discordgo.Session, i *discordgo.InteractionCreate) error
- func RespondEphemeral(s *discordgo.Session, i *discordgo.InteractionCreate, message string) error
- func RespondOrEdit(s *discordgo.Session, i *discordgo.InteractionCreate, ...) error
- type Button
- type Command
- type EmptyButton
- type EmptyCommand
- type EmptyHook
- type EmptyModal
- type ErrorHandler
- type Hook
- type IDMatcher
- type Modal
- type RecoverHandler
- type Router
- func (r *Router) AddButton(btn Button)
- func (r *Router) AddCommand(cmd Command)
- func (r *Router) AddEventHandler(h any)
- func (r *Router) AddModal(m Modal)
- func (r *Router) ClearButtons()
- func (r *Router) ClearCommands()
- func (r *Router) ClearModals()
- func (r *Router) Init()
- func (r *Router) RegisterCommands(guildID string) error
- type Scope
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnknownCommand = errors.New("unknown command") ErrUnknownButton = errors.New("unknown button") ErrUnknownModal = errors.New("unknown modal") ErrSessionNotReady = errors.New("session not ready") ErrHookAborted = errors.New("hook aborted") ErrNotACommand = errors.New("not an application command interaction") ErrCommandFailed = errors.New("command failed") ErrButtonFailed = errors.New("button failed") ErrModalFailed = errors.New("modal failed") )
errors returned by the router.
Functions ¶
func DefaultErrorHandler ¶
func DefaultErrorHandler(s *discordgo.Session, i *discordgo.InteractionCreate, err error)
DefaultErrorHandler responds with a default ephemeral error message.
func DefaultRecoverHandler ¶
func DefaultRecoverHandler(s *discordgo.Session, i *discordgo.InteractionCreate, recovered any, stack []byte)
DefaultRecoverHandler responds with an ephemeral error message and prints the stack trace.
func RespondEmptyAutocomplete ¶
func RespondEmptyAutocomplete(s *discordgo.Session, i *discordgo.InteractionCreate) error
RespondEmptyAutocomplete sends an empty autocomplete result list.
func RespondEphemeral ¶
RespondEphemeral is a shortcut for sending a simple ephemeral text message.
func RespondOrEdit ¶
func RespondOrEdit(s *discordgo.Session, i *discordgo.InteractionCreate, data *discordgo.InteractionResponseData) error
RespondOrEdit sends a response based on the current interaction state:
- Not yet responded → sends a new channel message response
- Deferred (loading state, no content) → edits the deferred message
- Already responded → sends a followup message
Types ¶
type Button ¶
type Button interface {
CustomID() string
Hooks() []Hook
Handle(ctx context.Context, s *discordgo.Session, i *discordgo.InteractionCreate) error
}
Button is a message component (button) handler.
type Command ¶
type Command interface {
Definition() *discordgo.ApplicationCommand
Scope() Scope
Hooks() []Hook
Handle(ctx context.Context, s *discordgo.Session, i *discordgo.InteractionCreate) error
Autocomplete(ctx context.Context, s *discordgo.Session, i *discordgo.InteractionCreate) error
}
Command is a slash command handler.
type EmptyButton ¶
type EmptyButton struct{}
EmptyButton provides default implementations for optional Button methods.
func (*EmptyButton) Hooks ¶
func (*EmptyButton) Hooks() []Hook
type EmptyCommand ¶
type EmptyCommand struct{}
EmptyCommand provides default implementations for optional Command methods.
func (*EmptyCommand) Autocomplete ¶
func (*EmptyCommand) Autocomplete(_ context.Context, s *discordgo.Session, i *discordgo.InteractionCreate) error
func (*EmptyCommand) Hooks ¶
func (*EmptyCommand) Hooks() []Hook
func (*EmptyCommand) Scope ¶
func (*EmptyCommand) Scope() Scope
type EmptyModal ¶
type EmptyModal struct{}
EmptyModal provides default implementations for optional Modal methods.
func (*EmptyModal) Hooks ¶
func (*EmptyModal) Hooks() []Hook
type ErrorHandler ¶
type ErrorHandler func(s *discordgo.Session, i *discordgo.InteractionCreate, err error)
ErrorHandler is called when a handler or hook returns an error. Replace Router.OnError to provide custom error handling behavior.
type Hook ¶
type Hook interface {
Execute(ctx context.Context, s *discordgo.Session, i *discordgo.InteractionCreate) error
}
Hook runs before a handler. Return an error to abort execution.
type IDMatcher ¶
IDMatcher determines whether a registered custom ID matches an incoming one. By default, exact string comparison is used.
type Modal ¶
type Modal interface {
CustomID() string
Hooks() []Hook
Handle(ctx context.Context, s *discordgo.Session, i *discordgo.InteractionCreate) error
}
Modal is a modal submit handler.
type RecoverHandler ¶
type RecoverHandler func(s *discordgo.Session, i *discordgo.InteractionCreate, recovered any, stack []byte)
RecoverHandler is called when a panic is caught during interaction handling. stack is the formatted goroutine stack trace.
type Router ¶
type Router struct {
IDMatcher IDMatcher
OnError ErrorHandler
// OnRecover is called when a handler panics.
// Set to nil to disable recovery and let panics propagate.
// Defaults to DefaultRecoverHandler.
OnRecover RecoverHandler
// contains filtered or unexported fields
}
Router dispatches Discord interactions to registered handlers.
func NewRouter ¶
NewRouter creates a Router with sane defaults: exact-match ID comparison, default error handler, and panic recovery enabled.
func (*Router) AddCommand ¶
func (*Router) AddEventHandler ¶
AddEventHandler registers a raw discordgo event handler (e.g. MessageCreate).
func (*Router) ClearButtons ¶
func (r *Router) ClearButtons()
func (*Router) ClearCommands ¶
func (r *Router) ClearCommands()
func (*Router) ClearModals ¶
func (r *Router) ClearModals()
func (*Router) Init ¶
func (r *Router) Init()
Init attaches the interaction dispatcher to the session.
func (*Router) RegisterCommands ¶
RegisterCommands bulk-registers all commands with Discord. guildID is optional; if empty, only global commands are registered.