Skip to content

Instantly share code, notes, and snippets.

@ioistired
Last active August 9, 2017 04:05
Show Gist options
  • Save ioistired/5acd66460be44ce2fa7281953d3c700e to your computer and use it in GitHub Desktop.
Save ioistired/5acd66460be44ce2fa7281953d3c700e to your computer and use it in GitHub Desktop.
Update your bot stats with bots.discord.pw
# for discord.py users
async def update_bot_stats():
"""inform bots.discord.pw of how many guilds the bot is in"""
async with aiohttp.ClientSession() as session:
print('Updating stats.')
print('Server count:', str(len(bot.servers)))
print('Auth token:', bot.discordpw_api_token)
print('Sending', '{{"server_count": {}}}'.format(len(bot.servers)))
async with session.post(
'https://bots.discord.pw/api/bots/{}/stats'.format(bot.user.id),
# manually format as JSON
# pfft, who needs `json.dumps()`?
data='{{"server_count": {}}}'.format(len(bot.servers)),
headers={
'Authorization': bot.discordpw_api_token,
'Content-Type': 'application/json',
},
) as resp:
print(await resp.text())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment