From 7433cf3b1663fdbcfbc08df241309eb4703531ca Mon Sep 17 00:00:00 2001 From: Rapptz Date: Mon, 6 Apr 2020 04:57:54 -0400 Subject: [PATCH] Fix VoiceClient.average_latency erroring when heartbeat is None --- discord/gateway.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/discord/gateway.py b/discord/gateway.py index f484c8e5f..5611e732b 100644 --- a/discord/gateway.py +++ b/discord/gateway.py @@ -752,8 +752,10 @@ class DiscordVoiceWebSocket(websockets.client.WebSocketClientProtocol): def average_latency(self): """:class:`list`: Average of last 20 HEARTBEAT latencies.""" heartbeat = self._keep_alive - average_latency = sum(heartbeat.recent_ack_latencies)/len(heartbeat.recent_ack_latencies) - return float('inf') if heartbeat is None else average_latency + if heartbeat is None: + return float('inf') + + return sum(heartbeat.recent_ack_latencies) / len(heartbeat.recent_ack_latencies) async def load_secret_key(self, data): log.info('received secret key for voice connection')