mirror of
https://github.com/uhIgnacio/EmoteManager.git
synced 2024-08-15 02:23:13 +00:00
fix AttributeError in on_shard_ready/update_shard
see Rapptz/discord.py#6652
This commit is contained in:
parent
25119e49f2
commit
2f4e0a3c28
1 changed files with 8 additions and 10 deletions
18
bot.py
18
bot.py
|
@ -76,10 +76,6 @@ class Bot(Bot):
|
|||
|
||||
# we use on_shard_ready rather than on_ready because the latter is a bit less reliable
|
||||
async def on_shard_ready(self, shard_id):
|
||||
guilds = [guild for guild in self.guilds if guild.shard_id == shard_id]
|
||||
guild_count = len(guilds)
|
||||
member_count = sum(guild.member_count for guild in guilds)
|
||||
|
||||
await self.pool.execute(
|
||||
"""
|
||||
INSERT INTO shard_info (shard_id, guild_count, member_count)
|
||||
|
@ -88,14 +84,10 @@ class Bot(Bot):
|
|||
guild_count = EXCLUDED.guild_count,
|
||||
member_count = EXCLUDED.member_count
|
||||
""",
|
||||
shard_id, guild_count, member_count,
|
||||
shard_id, *self.shard_stats(shard_id),
|
||||
)
|
||||
|
||||
async def update_shard(self, guild):
|
||||
guilds = [guild2 for guild2 in self.guilds if guild2.shard_id == guild.shard_id]
|
||||
guild_count = len(guilds)
|
||||
member_count = sum(guild.member_count for guild in guilds)
|
||||
|
||||
await self.pool.execute(
|
||||
"""
|
||||
UPDATE shard_info
|
||||
|
@ -104,11 +96,17 @@ class Bot(Bot):
|
|||
member_count = $3
|
||||
WHERE shard_id = $1
|
||||
""",
|
||||
guild.shard_id, guild_count, member_count,
|
||||
guild.shard_id, *self.shard_stats(guild.shard_id),
|
||||
)
|
||||
|
||||
on_guild_join = on_guild_remove = update_shard
|
||||
|
||||
def shard_stats(self, shard_id):
|
||||
guilds = [guild for guild in self.guilds if guild.shard_id == shard_id]
|
||||
guild_count = len(guilds)
|
||||
member_count = sum(getattr(guild, 'member_count', 0) for guild in guilds)
|
||||
return guild_count, member_count
|
||||
|
||||
def main():
|
||||
import sys
|
||||
|
||||
|
|
Loading…
Reference in a new issue