Skip to content

PycordBot

The bot is based on Pycord's discord.Bot class and only overrides or extends certain functionality described below.

Bases: Bot

Discord bot based on discord.Bot.

Attributes:

Name Type Description
config dict[str, Any]

Bot's configuration loaded from the configuration file or passed on initialization.

bot_locale BotLocale

Locale management instance with necessary helper methods.

default_locale str

Default locale used by the bot.

locales dict[str, Any]

Dictionary with locales. Key is the name of the locale and its value is the locale mapping.

scheduler AsyncIOScheduler | BackgroundScheduler | None

Scheduler instance passed on initialization based on APScheduler.

_ Callable

A shorthand for the BotLocale._() method using bot's instance.

in_all_locales Callable

A shorthand for the BotLocale.in_all_locales() method using bot's instance.

in_every_locale Callable

A shorthand for the BotLocale.in_every_locale() method using bot's instance.

__init__(*args, config=None, config_path=Path('config.json'), locales_root=None, scheduler=None, **kwargs)

Initializes PycordBot instance (child of discord.Bot).

Parameters:

Name Type Description Default
*args *tuple[Any]

Any positional arguments passed to the initialization of discord.Bot.

()
config dict[str, Any] | None

Bot's configuration. Not needed if config_path is passed. Defaults to None.

None
config_path str | Path

Path bot's configuration file. Not needed if config is passed. Defaults to None.

Path('config.json')
locales_root str | Path | None

Path to a directory where locale files are stored. Defaults to None, which will attempt to use locale/.

None
scheduler AsyncIOScheduler | BackgroundScheduler | None

Scheduler instance to use. Based on APScheduler. Defaults to None.

None
**kwargs **dict[str, Any]

Any keyword arguments passed to the initialization of discord.Bot.

{}

close(scheduler_shutdown=True, scheduler_wait=True) async

Closes the connection to Discord.

Parameters:

Name Type Description Default
scheduler_shutdown bool

Whether to shutdown the scheduler (if it is set) right before disconnecting from Discord. Defaults to True.

True
scheduler_wait bool

Whether to wait for the scheduler to finish all tasks before shutting down. Defaults to True.

True

start(token, reconnect=True, scheduler_start=True) async

A shorthand coroutine for login + connect.

Parameters:

Name Type Description Default
token str

Bot token used to connect to Discord.

required
reconnect bool

Whether an automatic reconnect should be attempted on lost connection. Defaults to True.

True
scheduler_start bool

Whether to start the scheduler (if it is set) right before connecting do Discord. Defaults to True.

True

Raises:

Type Description
TypeError

An unexpected keyword argument was received.