41 lines
1.0 KiB
Go
41 lines
1.0 KiB
Go
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.")
|
|
}
|