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
+44
View File
@@ -0,0 +1,44 @@
package commands
import (
"context"
"fmt"
"strings"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
)
type QueueCommand struct {
deps *Dependencies
}
func NewQueueCommand(deps *Dependencies) *QueueCommand {
return &QueueCommand{deps: deps}
}
func (c *QueueCommand) Definition() discord.ApplicationCommandCreate {
return discord.SlashCommandCreate{
Name: "queue",
Description: "Shows the upcoming tracks",
}
}
func (c *QueueCommand) Execute(ctx context.Context, event *events.ApplicationCommandInteractionCreate) error {
gid, ok := guildID(event)
if !ok {
return guildOnlyError(event)
}
tracks := c.deps.Music.Guild(gid).Queued()
if len(tracks) == 0 {
return reply(event, "The queue is empty.")
}
var builder strings.Builder
builder.WriteString("Up next:\n")
for i, track := range tracks {
fmt.Fprintf(&builder, "%d. **%s** (%s)\n", i+1, track.Info.Title, track.Info.Length)
}
return reply(event, builder.String())
}