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:
guild_id (
int
) – The ID of the guild used forwait_until_guild_available()
.allowed_roles (
list
) – A list of role IDs that the bot is allowed to mention.http_session (aiohttp.ClientSession) – The session to use for the bot.
redis_session (
Optional
[RedisSession
]) – The async_rediscache.RedisSession to use for the bot.api_client (
Optional
[APIClient
]) – Thepydis_core.site_api.APIClient
instance to use for the bot.statsd_url (
Optional
[str
]) – The URL of the statsd server to use for the bot. If not given, a dummy statsd client will be created.
- add_command(command)[source]¶
Add
command
as normal and then add its root aliases to the bot.- Return type:
- clear()[source]¶
Not implemented! Re-instantiate the bot instead of attempting to re-use a closed one.
- Return type:
- async close()[source]¶
Close the Discord connection, and the aiohttp session, connector, statsd client, and resolver.
- Return type:
- async load_extensions(module, sync_app_commands=True)[source]¶
Load all the extensions within the given
module
and save them toself.all_extensions
.
- 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:
Clear the internal guild available event when self.guild_id becomes unavailable.
- Return type:
- async ping_services()[source]¶
Ping all required services on setup to ensure they are up before starting.
- Return type:
- 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.
- async setup_hook()[source]¶
An async init to startup generic services.
Connects to statsd, and calls
AsyncStatsClient.create_socket
andping_services()
.- Return type:
- 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: