Posting to discordbotslist.com with aiohttp

Free lines Python 2 revisions 86 a month ago a month ago
import asyncio
import json
import aiohttp

class StatPoster:
    def __init__(self, bot):
        self.bot = bot
        self.token = 'yourtoken'
        self.dbl_header = {"Authorization": f"Bot {self.token}", "Content-Type": "application/json"}
        self.session = aiohttp.ClientSession(loop=bot.loop)

    async def poster(self):
        while True:
                dbl_payload = {"guilds": len(self.bot.guilds), "users": len(self.bot.users)), "voice_connections": len(self.bot.voice_clients) }
                async with self.session.post(f'https://discordbotlist.com/api/bots/{self.bot.id}/stats', headers=self.dbl_header, data=json.dumps(dbl_payload)) as dbl:
                    response = await dbl.text()
                    print('Guild count posted to DBL: [{}]: {}'.format(dbl.status, response))
            await asyncio.sleep(300)

def setup(bot):

aiohttp makes bot go fast zoooom