API Reference

The following section outlines the API of danbot-hosting-py.

Client

class danbot_api.DanBotClient(bot: discord.client.Client, *, key: str, session: Optional[aiohttp.client.ClientSession] = None, autopost: bool = False)

Represents a client connection that connects to the DanBotHosting API.

Parameters
  • bot (Union[discord.Client, discord.ext.commands.Bot])) – your discord.py client connection.

  • key (str) – the DanBot Hosting API key.

  • autopost (bool, default: False) – If you want to have autopost turned on/off.

  • session (Optional[aiohttp.ClientSession]) – If you want to have a custom ClientSession instance for sending requests.

async post(server_count: int, user_count: int)

Main post method

You don’t need to use this method if you have the autopost paremeter in the class set to True.

Parameters
  • server_count (int) – The server count you’re posting to the API

  • user_count (int) – The user count you’re posting to the API

Returns

The data posted to the API

Return type

Optinal[dict]

async get_bot_info(bot_id: Optional[int] = None)

a coroutine that gets bots’ infos from the API

Parameters

bot_id (Optional[int]) – The id of the bot you’re searching for. Defaults to the own bot’s

Returns

Data of the bot asked for, gotten from the API

Return type

Optional[dict]

async close()

Closes all of the connections.

Exceptions

exception danbot_api.DBHException

Bases: Exception

Base exception class for this module

So all of the errors/exceptions below/after this would be a subclass of this

exception danbot_api.HTTPException

Bases: danbot_api.errors.DBHException

The exception for the http errors

exception danbot_api.ServerError(status_code: int)

Bases: danbot_api.errors.HTTPException

Gives you this error when the response status is higher than 500

exception danbot_api.APIError(msg)

Bases: danbot_api.errors.HTTPException

Given when the API itself gives out an error

Event reference

danbot_api.on_dbh_post(data)

Called when the autopost successfully posts the data to the DBH API.

Parameters

data – The data that was posted to the API.

Example:

@bot.event
async def on_dbh_post(data):
    print(data)