Implement slash commands for playback control

This commit is contained in:
2026-09-21 18:48:17 +02:00
parent 347faf6b94
commit d05e721284
15 changed files with 809 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
package commands
import (
"context"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
)
type Command interface {
Definition() discord.ApplicationCommandCreate
Execute(ctx context.Context, event *events.ApplicationCommandInteractionCreate) error
}
type Registry struct {
commands map[string]Command
}
func NewRegistry(cmds ...Command) *Registry {
registry := &Registry{commands: make(map[string]Command, len(cmds))}
for _, cmd := range cmds {
registry.commands[cmd.Definition().CommandName()] = cmd
}
return registry
}
func (r *Registry) Get(name string) (Command, bool) {
cmd, ok := r.commands[name]
return cmd, ok
}
func (r *Registry) Definitions() []discord.ApplicationCommandCreate {
definitions := make([]discord.ApplicationCommandCreate, 0, len(r.commands))
for _, cmd := range r.commands {
definitions = append(definitions, cmd.Definition())
}
return definitions
}