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
+47
View File
@@ -0,0 +1,47 @@
package commands
import (
"context"
"fmt"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
)
type VolumeCommand struct {
deps *Dependencies
}
func NewVolumeCommand(deps *Dependencies) *VolumeCommand {
return &VolumeCommand{deps: deps}
}
func (c *VolumeCommand) Definition() discord.ApplicationCommandCreate {
return discord.SlashCommandCreate{
Name: "volume",
Description: "Sets the playback volume",
Options: []discord.ApplicationCommandOption{
discord.ApplicationCommandOptionInt{
Name: "level",
Description: "Volume percentage, 0-200 (default 100)",
Required: true,
MinValue: intPtr(0),
MaxValue: intPtr(200),
},
},
}
}
func (c *VolumeCommand) Execute(ctx context.Context, event *events.ApplicationCommandInteractionCreate) error {
gid, err := requirePlaybackAccess(c.deps.Discord, event)
if err != nil {
return err
}
level := event.SlashCommandInteractionData().Int("level")
if err := c.deps.Music.Guild(gid).SetVolume(ctx, level); err != nil {
return replyWithError(event, "Could not change the volume.", err)
}
return reply(event, fmt.Sprintf("Volume set to **%d%%**.", level))
}