From cfa2e874ed0efcb326f236e8388ff8c0d1aa5740 Mon Sep 17 00:00:00 2001 From: Manuel Raimo Date: Wed, 25 Oct 2023 20:50:30 +0200 Subject: [PATCH] fix: error checking and debug statement Trying to identify and fix a nil pointer somewhere along the chain --- main.go | 1 + manager/sound.go | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 3d6ece8..7c8cabc 100644 --- a/main.go +++ b/main.go @@ -278,6 +278,7 @@ func voiceStateUpdate(s *discordgo.Session, v *discordgo.VoiceStateUpdate) { // If the bot has been disconnected from the voice channel, reconnect it var err error + lit.Debug("Reconnecting to voice channel %s on guild %s", server[v.GuildID].VoiceChannel, v.GuildID) server[v.GuildID].VC, err = s.ChannelVoiceJoin(v.GuildID, server[v.GuildID].VoiceChannel, false, true) if err != nil { lit.Error("Can't join voice channel, %s", err) diff --git a/manager/sound.go b/manager/sound.go index 699bfa3..19ba9a6 100644 --- a/manager/sound.go +++ b/manager/sound.go @@ -6,6 +6,7 @@ import ( "github.com/TheTipo01/YADMB/api/notification" "github.com/TheTipo01/YADMB/constants" "github.com/TheTipo01/YADMB/queue" + "github.com/bwmarrin/lit" "io" "os" ) @@ -81,7 +82,13 @@ func (server *Server) playSound(el *queue.Element) (SkipReason, error) { return Error, err } - server.VC.OpusSend <- InBuf + if server.VC != nil { + server.VC.OpusSend <- InBuf + } else { + lit.Debug("VC is nil, triggering reconnection") + server.VC, _ = server.Clients.Discord.ChannelVoiceJoin(server.GuildID, server.VoiceChannel, false, true) + } + } } }