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
+40
View File
@@ -0,0 +1,40 @@
package commands
import (
"context"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
)
type StopCommand struct {
deps *Dependencies
}
func NewStopCommand(deps *Dependencies) *StopCommand {
return &StopCommand{deps: deps}
}
func (c *StopCommand) Definition() discord.ApplicationCommandCreate {
return discord.SlashCommandCreate{
Name: "stop",
Description: "Stops playback, clears the queue and leaves the voice channel",
}
}
func (c *StopCommand) Execute(ctx context.Context, event *events.ApplicationCommandInteractionCreate) error {
gid, err := requirePlaybackAccess(c.deps.Discord, event)
if err != nil {
return err
}
if err := c.deps.Music.Guild(gid).Stop(ctx); err != nil {
return replyWithError(event, "Could not stop playback.", err)
}
if err := c.deps.Discord.UpdateVoiceState(ctx, gid, nil, false, false); err != nil {
return replyWithError(event, "Stopped playback, but could not leave the voice channel.", err)
}
return reply(event, "Stopped playback and left the voice channel.")
}