Pydis Core

Useful utilities and tools for Discord bot development.

class BotBase(*args, guild_id, allowed_roles, http_session, redis_session=None, api_client=None, statsd_url=None, **kwargs)[source]

Bases: Bot

A sub-class that implements many common features that Python Discord bots use.

__init__(*args, guild_id, allowed_roles, http_session, redis_session=None, api_client=None, statsd_url=None, **kwargs)[source]

Initialise the base bot instance.

Parameters:
async add_cog(cog)[source]

Add the given cog to the bot and log the operation.

Return type:

None

add_command(command)[source]

Add command as normal and then add its root aliases to the bot.

Return type:

None

clear()[source]

Not implemented! Re-instantiate the bot instead of attempting to re-use a closed one.

Return type:

None

async close()[source]

Close the Discord connection, and the aiohttp session, connector, statsd client, and resolver.

Return type:

None

async load_extensions(module)[source]

Load all the extensions within the given module and save them to self.all_extensions.

This should be ran in a task on the event loop to avoid deadlocks caused by wait_for calls.

Return type:

None

async log_to_dev_log(message)[source]

Log the given message to #dev-log.

Return type:

None

async on_guild_available(guild)[source]

Set the internal guild available event when self.guild_id becomes available.

If the cache appears to still be empty (no members, no channels, or no roles), the event will not be set and guild_available_but_cache_empty event will be emitted.

Return type:

None

async on_guild_unavailable(guild)[source]

Clear the internal guild available event when self.guild_id becomes unavailable.

Return type:

None

async ping_services()[source]

Ping all required services on setup to ensure they are up before starting.

Return type:

None

remove_command(name)[source]

Remove a command/alias as normal and then remove its root aliases from the bot.

Individual root aliases cannot be removed by this function. To remove them, either remove the entire command or manually edit bot.all_commands.

Return type:

Optional[Command]

async setup_hook()[source]

An async init to startup generic services.

Connects to statsd, and calls AsyncStatsClient.create_socket and ping_services().

Return type:

None

async wait_until_guild_available()[source]

Wait until the guild that matches the guild_id given at init is available (and the cache is ready).

The on_ready event is inadequate because it only waits 2 seconds for a GUILD_CREATE gateway event before giving up and thus not populating the cache for unavailable guilds.

Return type:

None

exception StartupError(base)[source]

Bases: Exception

Exception class for startup errors.

__init__(base)[source]

Subpackages

Submodules