diff --git a/MusicBot/main.py b/MusicBot/main.py index 2b7fc88..e86606c 100644 --- a/MusicBot/main.py +++ b/MusicBot/main.py @@ -1,8 +1,10 @@ import os import logging +from aiohttp import ClientSession import discord from discord.ext.commands import Bot +from discord.ext import tasks intents = discord.Intents.default() bot = Bot(intents=intents) @@ -18,6 +20,22 @@ async def on_ready(): logging.info("Bot's ready!") await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name="/voice vibe")) +@tasks.loop(seconds=3600) +async def update_server_count(): + # Don't update server count in debug mode + if os.getenv('DEBUG') == 'True': + return + + async with ClientSession() as session: + if token := os.getenv('PROMO_TOKEN_1'): + res = await session.post( + 'https://api.server-discord.com/v2/bots/1325795708019806250/stats', + headers={'Authorization': token}, + data={'servers': len(bot.guilds), 'shards': bot.shard_count or 1} + ) + if not res.ok: + logging.error(f'Failed to update server count 1: {res.status} {await res.text()}') + if __name__ == '__main__': from dotenv import load_dotenv load_dotenv()