-
Notifications
You must be signed in to change notification settings - Fork 3
/
TopGG.py
32 lines (25 loc) · 1013 Bytes
/
TopGG.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import discord
from discord.ext import commands, tasks
import settings
import asyncio
import requests
endpoint_url="https://top.gg/api"
class TopGG(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.token = settings.TopGGtoken # set this to your DBL token
self.update_stats.start()
def cog_unload(self):
self.update_stats.cancel()
@tasks.loop(minutes=15.0)
async def update_stats(self):
header={"Authorization": self.token}
print('Attempting to post server count')
try:
data={"server_count": int(len(self.bot.guilds))}
requests.post("{endpoint}/bots/{bot_id}/stats".format(endpoint=endpoint_url, bot_id=str(self.bot.user.id)), data=data, headers=header)
print('Posted server count ({})'.format(len(self.bot.guilds)))
except Exception as e:
print('Failed to post server count\n{}: {}'.format(type(e).__name__, e))
def setup(client):
client.add_cog(TopGG(client))