diff options
| author | Bobby <[email protected]> | 2025-04-13 18:41:17 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2025-04-13 18:41:17 +0530 |
| commit | 6b486844a18fe8bf9b4ca4bdd3c44f45094e03e5 (patch) | |
| tree | b2655928e1fd60516619359ba214015084b05b9c /commands/disconnect.go | |
| parent | f884a0fe47f7403850de650d3be3733420ac5986 (diff) | |
| download | ai-6b486844a18fe8bf9b4ca4bdd3c44f45094e03e5.tar.xz ai-6b486844a18fe8bf9b4ca4bdd3c44f45094e03e5.zip | |
refactor; add logging; add disconnect; supress opus warnings
Diffstat (limited to 'commands/disconnect.go')
| -rw-r--r-- | commands/disconnect.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/commands/disconnect.go b/commands/disconnect.go new file mode 100644 index 0000000..94249c8 --- /dev/null +++ b/commands/disconnect.go @@ -0,0 +1,55 @@ +package commands + +import ( + "ai/utils/music" + "fmt" + + "github.com/bwmarrin/discordgo" +) + +func Disconnect(s *discordgo.Session, i *discordgo.InteractionCreate) { + guildID := i.GuildID + userID := i.Member.User.ID + + isSameVC, userChannelID := music.IsUserInSameVC(s, guildID, userID) + + if userChannelID == "" { + respondWithError(s, i, "You must be in a voice channel to use this command.") + return + } + + voice, exists := music.VoiceConnection[guildID] + if !exists { + respondWithError(s, i, "I'm not in a voice channel.") + return + } + + if !isSameVC { + channel, err := s.Channel(voice.ChannelID) + if err == nil { + respondWithError(s, i, fmt.Sprintf("You must be in the same voice channel as me (**%s**) to use this command.", channel.Name)) + } else { + respondWithError(s, i, "You must be in the same voice channel as me to use this command.") + } + return + } + + channel, err := s.Channel(voice.ChannelID) + channelName := "voice channel" + if err == nil { + channelName = channel.Name + } + + err = music.LeaveVoiceChannel(guildID) + if err != nil { + respondWithError(s, i, fmt.Sprintf("Error disconnecting from voice channel: %v", err)) + return + } + + s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ + Type: discordgo.InteractionResponseChannelMessageWithSource, + Data: &discordgo.InteractionResponseData{ + Content: fmt.Sprintf("✅ Disconnected from **%s**.", channelName), + }, + }) +} |
