Skip to content

Commit

Permalink
fix: error checking and debug statement
Browse files Browse the repository at this point in the history
Trying to identify and fix a nil pointer somewhere along the chain
  • Loading branch information
TheTipo01 committed Oct 25, 2023
1 parent 4b58db7 commit cfa2e87
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion manager/sound.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
}

}
}
}
Expand Down

0 comments on commit cfa2e87

Please sign in to comment.