Files

48 lines
1.2 KiB
Go

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))
}