A simple API wrapper for Top.gg written in Python.
Project description
A simple API wrapper for Top.gg written in Python, supporting discord.py.
Installation
Install via pip (recommended)
pip3 install topggpy
Install from source
pip3 install git+https://github.com/top-gg/python-sdk/
Documentation
Documentation can be found here
Features
POST server count
GET bot info, server count, upvote info
GET all bots
GET user info
GET widgets (large and small) including custom ones. See docs.top.gg for more info.
GET weekend status
Built-in webhook to handle Top.gg votes
Automated server count posting
Searching for bots via the API
Additional information
Before using the webhook provided by this library, make sure that you have specified port open.
Optimal values for port are between 1024 and 49151.
If you happen to need help implementing topggpy in your bot, feel free to ask in the #development or #api channels in our Discord server.
Examples
Posting server count manually every 30 minutes:
from discord.ext import tasks
import dbl
# This example uses tasks provided by discord.ext to create a task that posts guild count to Top.gg every 30 minutes.
dbl_token = 'Top.gg token' # set this to your bot's Top.gg token
bot.topggpy = dbl.DBLClient(bot, dbl_token)
@tasks.loop(minutes=30)
async def update_stats():
"""This function runs every 30 minutes to automatically update your server count."""
try:
await bot.topggpy.post_guild_count()
print(f'Posted server count ({bot.topggpy.guild_count})')
except Exception as e:
print('Failed to post server count\n{}: {}'.format(type(e).__name__, e))
update_stats.start()
Using webhook:
import dbl
# This example uses topggpy's webhook system.
# In order to run the webhook, at least webhook_port argument must be specified (number between 1024 and 49151).
dbl_token = 'Top.gg token' # set this to your bot's Top.gg token
bot.topggpy = dbl.DBLClient(bot, dbl_token, webhook_path='/dblwebhook', webhook_auth='password', webhook_port=5000)
@bot.event
async def on_dbl_vote(data):
"""An event that is called whenever someone votes for the bot on Top.gg."""
print(f"Received a vote:\n{data}")
@bot.event
async def on_dbl_test(data):
"""An event that is called whenever someone tests the webhook system for your bot on Top.gg."""
print(f"Received a test vote:\n{data}")
With autopost:
import dbl
# This example uses topggpy's autopost feature to post guild count to Top.gg every 30 minutes.
dbl_token = 'Top.gg token' # set this to your bot's Top.gg token
bot.topggpy = dbl.DBLClient(bot, dbl_token, autopost=True)
@bot.event
async def on_guild_post():
print(f'Posted server count ({bot.topggpy.guild_count})')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.