dgx

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 Defer

func Defer(s *discordgo.Session, i *discordgo.InteractionCreate, ephemeral bool) error

Set ephemeral flag to make the eventual message visible only to the invoking user.

func RespondEmptyAutocomplete

func RespondEmptyAutocomplete(s *discordgo.Session, i *discordgo.InteractionCreate) error

RespondEmptyAutocomplete sends an empty autocomplete result list.

func RespondEphemeral

func RespondEphemeral(s *discordgo.Session, i *discordgo.InteractionCreate, message string) error

RespondEphemeral is a shortcut for sending a simple ephemeral text message.

func RespondOrEdit

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) Hooks

func (*EmptyCommand) Hooks() []Hook

func (*EmptyCommand) Scope

func (*EmptyCommand) Scope() Scope

type EmptyHook

type EmptyHook struct{}

EmptyHook provides a no-op Execute implementation.

func (*EmptyHook) Execute

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

type IDMatcher func(registered, incoming string) bool

IDMatcher determines whether a registered custom ID matches an incoming one. By default, exact string comparison is used.

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

func NewRouter(session *discordgo.Session) *Router

NewRouter creates a Router with sane defaults: exact-match ID comparison, default error handler, and panic recovery enabled.

func (*Router) AddButton

func (r *Router) AddButton(btn Button)

func (*Router) AddCommand

func (r *Router) AddCommand(cmd Command)

func (*Router) AddEventHandler

func (r *Router) AddEventHandler(h any)

AddEventHandler registers a raw discordgo event handler (e.g. MessageCreate).

func (*Router) AddModal

func (r *Router) AddModal(m Modal)

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

func (r *Router) RegisterCommands(guildID string) error

RegisterCommands bulk-registers all commands with Discord. guildID is optional; if empty, only global commands are registered.

type Scope

type Scope int

Scope defines where a command is registered.

const (
	ScopeGlobal Scope = iota
	ScopeGuild
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL