Bot now keeps voice connections established
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user