From e573d6da44036c97b43c1f160fa71e194535f26e Mon Sep 17 00:00:00 2001 From: Mitchell Date: Tue, 24 Nov 2020 20:50:23 -0600 Subject: [PATCH] fix: attempt fixing voice disconnections --- config.template.json | 3 ++- server/bot/bot.go | 10 ++++++++++ server/bothandlers/sounds.go | 8 +++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/config.template.json b/config.template.json index fa16b5e..60ae919 100644 --- a/config.template.json +++ b/config.template.json @@ -8,5 +8,6 @@ "bot_prefix": "#", "jwt_secret": "generate a random secret string here", - "server_addr": "0.0.0.0:80" + "server_addr": "0.0.0.0:80", + "logger": true } diff --git a/server/bot/bot.go b/server/bot/bot.go index dee2e24..a08fcfd 100644 --- a/server/bot/bot.go +++ b/server/bot/bot.go @@ -46,6 +46,16 @@ func Start(token string) *discordgo.Session { } }) + // We need information about guilds (which includes their channels), + // messages and voice states. + _session.Identify.Intents = discordgo.MakeIntent( + discordgo.IntentsGuilds | + discordgo.IntentsGuildMessages | + discordgo.IntentsGuildVoiceStates | + discordgo.IntentsGuildMessages | + discordgo.IntentsGuildMessageReactions | + discordgo.IntentsAllWithoutPrivileged) + // start listening for commands // Open the websocket and begin listening. err := _session.Open() diff --git a/server/bothandlers/sounds.go b/server/bothandlers/sounds.go index c562357..679b910 100644 --- a/server/bothandlers/sounds.go +++ b/server/bothandlers/sounds.go @@ -153,12 +153,18 @@ func (conn *AudioConnection) summon(m *discordgo.MessageCreate) { for _, vs := range g.VoiceStates { if vs.UserID == m.Author.ID { - conn.VoiceConnection, err = conn.Session.ChannelVoiceJoin(g.ID, vs.ChannelID, false, false) + _, err = conn.Session.ChannelVoiceJoin(g.ID, vs.ChannelID, false, false) if err != nil { log.Error(err) return } + if _, ok := conn.Session.VoiceConnections[c.GuildID]; ok { + conn.VoiceConnection = conn.Session.VoiceConnections[c.GuildID] + } else { + log.Error("Voice connection not found on discord object") + return + } // set the current channel conn.CurrentChannel = c