Bot now keeps voice connections established

This commit is contained in:
da
2017-01-31 22:59:12 +01:00
parent f4b8a5f308
commit 2441e65072
+9 -4
View File
@@ -308,9 +308,15 @@ func playSound(play *Play, vc *discordgo.VoiceConnection) (err error) {
"play": play, "play": play,
}).Info("Playing sound") }).Info("Playing sound")
if vc != nil {
if vc.GuildID != play.GuildID {
vc.Disconnect()
vc = nil
}
}
if vc == nil { if vc == nil {
vc, err = discord.ChannelVoiceJoin(play.GuildID, play.ChannelID, false, false) vc, err = discord.ChannelVoiceJoin(play.GuildID, play.ChannelID, false, true)
// vc.Receive = false
if err != nil { if err != nil {
log.WithFields(log.Fields{ log.WithFields(log.Fields{
"error": err, "error": err,
@@ -324,7 +330,7 @@ func playSound(play *Play, vc *discordgo.VoiceConnection) (err error) {
// If we need to change channels, do that now // If we need to change channels, do that now
if vc.ChannelID != play.ChannelID { if vc.ChannelID != play.ChannelID {
vc.ChangeChannel(play.ChannelID, false, false) vc.ChangeChannel(play.ChannelID, false, true)
time.Sleep(time.Millisecond * 125) time.Sleep(time.Millisecond * 125)
} }
@@ -350,7 +356,6 @@ func playSound(play *Play, vc *discordgo.VoiceConnection) (err error) {
time.Sleep(time.Millisecond * time.Duration(play.Sound.PartDelay)) time.Sleep(time.Millisecond * time.Duration(play.Sound.PartDelay))
mutex.Lock() mutex.Lock()
delete(queues, play.GuildID) delete(queues, play.GuildID)
vc.Disconnect()
mutex.Unlock() mutex.Unlock()
return nil return nil
} }