Skip to main content

A simple API wrapper for top.gg written in Python.

Project description

View on PyPi v0.3.3 Documentation Status

A simple API wrapper for top.gg written in Python

Installation

Install via pip (recommended)

pip install dblpy

Install from source

pip install git+https://github.com/top-gg/DBL-Python-Library

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 top.gg/api/docs for more info.

  • GET weekend status

  • Built-in webhook to help you handle top.gg upvotes

  • 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.

  • webhook_port must be between 1024 and 49151.

  • Below examples are to be used as discord.py cogs. If you need help adding them to your bot, feel free to ask in the #development channel in our Discord server.

Examples

Posting server count manually:

from discord.ext import commands, tasks

import dbl


class TopGG(commands.Cog):
    """
    This example uses tasks provided by discord.ext to create a task that posts guild count to top.gg every 30 minutes.
    """

    def __init__(self, bot):
        self.bot = bot
        self.token = 'dbl_token'  # set this to your DBL token
        self.dblpy = dbl.DBLClient(self.bot, self.token)
        self.update_stats.start()

    def cog_unload(self):
        self.update_stats.cancel()

    @tasks.loop(minutes=30)
    async def update_stats(self):
        """This function runs every 30 minutes to automatically update your server count."""
        await self.bot.wait_until_ready()
        try:
            server_count = len(self.bot.guilds)
            await self.dblpy.post_guild_count(server_count)
            print('Posted server count ({})'.format(server_count))
        except Exception as e:
            print('Failed to post server count\n{}: {}'.format(type(e).__name__, e))


def setup(bot):
    bot.add_cog(TopGG(bot))

Using webhook:

from discord.ext import commands

import dbl


class TopGG(commands.Cog):
    """
    This example uses dblpy's webhook system.
    In order to run the webhook, at least webhook_port must be specified (number between 1024 and 49151).
    """

    def __init__(self, bot):
        self.bot = bot
        self.token = 'dbl_token'  # set this to your DBL token
        self.dblpy = dbl.DBLClient(self.bot, self.token, webhook_path='/dblwebhook', webhook_auth='password', webhook_port=5000)

    @commands.Cog.listener()
    async def on_dbl_vote(self, data):
        """An event that is called whenever someone votes for the bot on top.gg."""
        print("Received an upvote:", "\n", data, sep="")

    @commands.Cog.listener()
    async def on_dbl_test(self, data):
        """An event that is called whenever someone tests the webhook system for your bot on top.gg."""
        print("Received a test upvote:", "\n", data, sep="")


def setup(bot):
    bot.add_cog(TopGG(bot))

With autopost:

from discord.ext import commands

import dbl


class TopGG(commands.Cog):
    """
    This example uses dblpy's autopost feature to post guild count to top.gg every 30 minutes.
    """

    def __init__(self, bot):
        self.bot = bot
        self.token = 'dbl_token'  # set this to your DBL token
        self.dblpy = dbl.DBLClient(self.bot, self.token, autopost=True)  # Autopost will post your guild count every 30 minutes

    @commands.Cog.listener()
    async def on_guild_post(self):
        print("Server count posted successfully")


def setup(bot):
    bot.add_cog(TopGG(bot))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dblpy-0.4.0.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

dblpy-0.4.0-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file dblpy-0.4.0.tar.gz.

File metadata

  • Download URL: dblpy-0.4.0.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.3

File hashes

Hashes for dblpy-0.4.0.tar.gz
Algorithm Hash digest
SHA256 744f5ee9493a945e5907466754b2dce4735715b34daabb9e6264f76ec79818c9
MD5 298221ad5e7ba5a827cd5f056447a07e
BLAKE2b-256 9bfe75c5f60c16f0566c934d1e8d3dbfdafdca464e5451a3c4d980469cb4033b

See more details on using hashes here.

File details

Details for the file dblpy-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: dblpy-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.3

File hashes

Hashes for dblpy-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2d7d746ee7e7b3a2597f485ebf4089e7baabdcf1717743228991bd988c69e1b5
MD5 a54bc8b62fb4175e7e415e2e4bf0257b
BLAKE2b-256 3378e9f2374d013eb51ba866e872a289940461577e24776208ef7f6e60d9ef6d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page