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
+62
View File
@@ -0,0 +1,62 @@
package commands
import (
"context"
"fmt"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"discord-music-bot/internal/music"
)
type LoopCommand struct {
deps *Dependencies
}
func NewLoopCommand(deps *Dependencies) *LoopCommand {
return &LoopCommand{deps: deps}
}
func (c *LoopCommand) Definition() discord.ApplicationCommandCreate {
return discord.SlashCommandCreate{
Name: "loop",
Description: "Sets what happens when a track finishes",
Options: []discord.ApplicationCommandOption{
discord.ApplicationCommandOptionString{
Name: "mode",
Description: "Loop mode",
Required: true,
Choices: []discord.ApplicationCommandOptionChoiceString{
{Name: "Off", Value: "off"},
{Name: "Track", Value: "track"},
{Name: "Queue", Value: "queue"},
},
},
},
}
}
func (c *LoopCommand) Execute(ctx context.Context, event *events.ApplicationCommandInteractionCreate) error {
gid, err := requirePlaybackAccess(c.deps.Discord, event)
if err != nil {
return err
}
value := event.SlashCommandInteractionData().String("mode")
var mode music.LoopMode
switch value {
case "off":
mode = music.LoopOff
case "track":
mode = music.LoopTrack
case "queue":
mode = music.LoopQueue
default:
return rejectEphemeral(event, fmt.Sprintf("Unknown loop mode %q.", value))
}
c.deps.Music.Guild(gid).SetLoopMode(mode)
return reply(event, fmt.Sprintf("Loop mode set to **%s**.", mode))
}