Documentation
¶
Index ¶
- func AttachHandlers[C Command, M Message](frame *Frame, refs ...SlashCommandHandlerRef[C, M])
- func PointerOf[T any](v T) (p *T)
- func RegisterShutdownFunc(ctx context.Context, f func()) (stop func() bool)
- func WaitUntilCleanShutdown(timeout time.Duration)
- type Command
- type CommandHandler
- type Error
- type Frame
- type Message
- type SlashCommandHandlerRef
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AttachHandlers ¶
func AttachHandlers[C Command, M Message](frame *Frame, refs ...SlashCommandHandlerRef[C, M])
AttachHandlers attaches the given command handlers to the given BotBuilder instance so they can be used in the command event listener.
func RegisterShutdownFunc ¶ added in v0.3.0
RegisterShutdownFunc adds a function which should be called after the passed context has been canceled. This function should be called in conjunction with WaitUntilCleanShutdown to ensure all passed shutdown functions have had time to exit cleanly.
func WaitUntilCleanShutdown ¶ added in v0.3.0
WaitUntilCleanShutdown waits until all shutdown functions have completed or the supplied duration passes, which ever happens first.
Types ¶
type Command ¶
type Command interface {
discord.SlashCommandCreate | discord.ApplicationCommandOptionSubCommand
}
Command is a type constraint for different command types that we can attach a handler to.
type CommandHandler ¶
type CommandHandler[M Message] func( ctx context.Context, event *events.ApplicationCommandInteractionCreate, logger *slog.Logger, ) (message M, err error)
CommandHandler is a function signature for a function used to respond to an invocation of a Discord slash command. A handler that returns the type discord.MessageUpdate must call event.DeferMessageCreate otherwise sending the response will always fail.
type Error ¶
Error is a union of two errors. One for internal use and another that is to be displayed to the user.
func (Error) Presentable ¶
Presentable returns the displayable error formatted with proper punctuation. Works with joined errors.
type Frame ¶
type Frame struct {
Client bot.Client
Commands []discord.ApplicationCommandCreate
EventListeners events.ListenerAdapter
// contains filtered or unexported fields
}
Frame is a Discord bot implementation that is designed for ease of setup and expansion.
func (*Frame) Start ¶
Start configures the bot with the given key and configuration options, connects it to the Discord API gateway, and configures provided slash commands.
If an API key is not provided when calling this function, it will be read from the DISCORD_TOKEN environment variable.
By default, the standard gateway configuration is used and a slash command event listener is configured based on the attached handlers.
For testing purposes, you can set the TEST_GUILD_ID environment variable with the ID of a Discord guild (aka server), and the slash commands will only be propogated to that specific guild.
type Message ¶
type Message interface {
discord.MessageCreate | discord.MessageUpdate
}
Message is a type constraint for different message types that can be returned by a CommandHandler function.
type SlashCommandHandlerRef ¶
type SlashCommandHandlerRef[C Command, M Message] struct { Command *C Handler CommandHandler[M] }
SlashCommandHandlerRef points to a command somewhere in the command trie and attaches a handler function to it.