mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-10-24 01:53:01 +00:00
Fixed a zero division error when accessing latencies
When accessing the latencies property on an AutoShardedClient when none of shards are ready, we get a ZeroDivisionError. An example of this can be seen here.
```py
class StatsBot(commands.AutoShardedBot):
def __init__(self):
super().__init__(command_prefix=None)
self._add_commands()
def _add_commands(self):
'''Adds commands automatically'''
for name, attr in inspect.getmembers(self):
if isinstance(attr, commands.Command):
self.add_command(attr)
```
When iterating through this custom client's it accesses the latencies property when no shards are ready, therefore it raises the error. A quick fix for this would be to return None if no shards are ready.
This commit is contained in:
@@ -175,8 +175,10 @@ class AutoShardedClient(Client):
|
||||
|
||||
This operates similarly to :meth:`.Client.latency` except it uses the average
|
||||
latency of every shard's latency. To get a list of shard latency, check the
|
||||
:attr:`latencies` property.
|
||||
:attr:`latencies` property. Returns ``nan`` if there are no shards ready.
|
||||
"""
|
||||
if not self.shards:
|
||||
return float('nan')
|
||||
return sum(latency for _, latency in self.latencies) / len(self.shards)
|
||||
|
||||
@property
|
||||
|
||||
Reference in New Issue
Block a user