A simple API wrapper for discordbots.org written in Python
Project description
A simple API wrapper for discordbots.org written in Python
Installation
Install via pip (recommended)
pip install dblpy
Install from source
pip install git+https://github.com/DiscordBotList/DBL-Python-Library
Documentation
Documentation can be found here
Working
POST server count
GET bot info, server count, upvote count, upvote info
GET all bots
GET user info
GET widgets (large and small) including custom ones. See discordbots.org/api/docs for more info.
GET weekend status
Webhook
Not Working / Implemented
Searching for bots via the api
Additional information
Before using the webhook provided by this library, make sure that you have port 5000 open.
Examples
import dbl
import discord
from discord.ext import commands
import asyncio
import logging
class DiscordBotsOrgAPI(commands.Cog):
"""Handles interactions with the discordbots.org API"""
def __init__(self, bot):
self.bot = bot
self.token = 'dbl_token' # set this to your DBL token
self.dblpy = dbl.Client(self.bot, self.token)
self.updating = self.bot.loop.create_task(self.update_stats())
async def update_stats(self):
"""This function runs every 30 minutes to automatically update your server count"""
await self.bot.wait_until_ready() # this is important, do not touch it
while self.bot.is_ready():
logger.info('Attempting to post server count')
try:
await self.dblpy.post_guild_count()
logger.info('Posted server count ({})'.format(self.dblpy.guild_count()))
except Exception as e:
logger.exception('Failed to post server count\n{}: {}'.format(type(e).__name__, e))
await asyncio.sleep(1800)
def setup(bot):
global logger
logger = logging.getLogger('bot')
bot.add_cog(DiscordBotsOrgAPI(bot))
import dbl
import discord
from discord.ext import commands
import asyncio
import logging
class DiscordBotsOrgAPI(commands.Cog):
"""Handles interactions with the discordbots.org API"""
def __init__(self, bot):
self.bot = bot
self.token = 'dbl_token' # set this to your DBL token
self.dblpy = dbl.Client(self.bot, self.token, webhook_path='/dblwebhook', webhook_auth='password', webhook_port=5000)
self.updating = self.bot.loop.create_task(self.update_stats())
async def update_stats(self):
"""This function runs every 30 minutes to automatically update your server count"""
await self.bot.wait_until_ready() # this is important, do not touch it
while self.bot.is_ready():
logger.info('Attempting to post server count')
try:
await self.dblpy.post_guild_count()
logger.info('Posted server count ({})'.format(self.dblpy.guild_count()))
except Exception as e:
logger.exception('Failed to post server count\n{}: {}'.format(type(e).__name__, e))
await asyncio.sleep(1800)
@commands.Cog.listener()
async def on_dbl_vote(self, data):
print(data)
def setup(bot):
global logger
logger = logging.getLogger('bot')
bot.add_cog(DiscordBotsOrgAPI(bot))
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.
Source Distribution
dblpython-0.2.1.tar.gz
(9.2 kB
view hashes)