1
0
mirror of https://github.com/mgerb/go-discord-bot synced 2026-01-08 08:02:49 +00:00

fix: attempt fixing voice disconnections

This commit is contained in:
2020-11-24 20:50:23 -06:00
parent 5052e647d2
commit e573d6da44
3 changed files with 19 additions and 2 deletions

View File

@@ -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
}

View File

@@ -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()

View File

@@ -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