From bbd49d1544c5125280c2d1465763315eeb8b4564 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 28 Mar 2020 18:43:42 +0100 Subject: [PATCH] Fix find_voice_player --- royalnet/serf/discord/discordserf.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/royalnet/serf/discord/discordserf.py b/royalnet/serf/discord/discordserf.py index c8841f7d..690fdafe 100644 --- a/royalnet/serf/discord/discordserf.py +++ b/royalnet/serf/discord/discordserf.py @@ -238,10 +238,12 @@ class DiscordSerf(Serf): return channels[0] def find_voice_player(self, guild: "discord.Guild") -> Optional[VoicePlayer]: - for voice_player in self.voice_players: - if not voice_player.voice_client.is_connected(): + candidate_players: List[VoicePlayer] = [] + for player in self.voice_players: + player: VoicePlayer + if not player.voice_client.is_connected(): continue - if voice_player.voice_client.guild == guild: - return voice_player - else: - return None + if guild is not None and guild != player.voice_client.guild: + continue + candidate_players.append(player) + return candidate_players[0] if len(candidate_players) > 0 else None