update guild count live

This commit is contained in:
io 2021-06-03 08:30:26 +00:00
parent 5054a8f68f
commit 25119e49f2
1 changed files with 18 additions and 0 deletions

18
bot.py
View File

@ -91,6 +91,24 @@ class Bot(Bot):
shard_id, guild_count, member_count,
)
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
SET
guild_count = $2,
member_count = $3
WHERE shard_id = $1
""",
guild.shard_id, guild_count, member_count,
)
on_guild_join = on_guild_remove = update_shard
def main():
import sys