Documentation ¶
Index ¶
- Variables
- func AddHandler[T any](ctx context.Context, dg *discordgo.Session, ...) func()
- func Run(ctx context.Context, setup func(*Setup) error) error
- func SetupResponse(dg *discordgo.Session, i *discordgo.Interaction) error
- func UpdateResponse(dg *discordgo.Session, i *discordgo.Interaction, content string) error
- type Setup
Constants ¶
This section is empty.
Variables ¶
var ErrNoToken = errors.New("DISCORD_TOKEN environment variable not set")
ErrNoToken is returned by Run if the token could not be found.
Functions ¶
func AddHandler ¶
func AddHandler[T any](ctx context.Context, dg *discordgo.Session, h func(context.Context, *discordgo.Session, T)) func()
AddHandler adds an event handler to a discordgo.Session, but includes an extra context argument and panic protection. The context provided to the handler itself will be a child of ctx that will be canceled when the handler returns.
func Run ¶
Run runs a Discord bot. It pulls the auth token from the $DISCORD_TOKEN environment variable, connects to Discord's API, then calls the provided setup function. When the provided context is canceled, it will exit, cleaning up whatever it did while setting up.
func SetupResponse ¶
func SetupResponse(dg *discordgo.Session, i *discordgo.Interaction) error
SetupResponse sets up the interaction for a deferred response.
func UpdateResponse ¶
UpdateResponse sets the content of a deferred interaction response as set up by [setupResponse].
Types ¶
type Setup ¶
type Setup struct {
// contains filtered or unexported fields
}
Setup is a wrapper that helps with setting up the configuration for a bot.
func (*Setup) RegisterCommands ¶
func (s *Setup) RegisterCommands(commands iter.Seq[*discordgo.ApplicationCommand])
RegisterCommands registers a set of commands with the underlying discordgo.Session for every guild that the bot is in. When the bot exits, the commands will be automatically unregistered.