Cog Manager

class redbot.core.cog_manager.CogManager(paths: typing.Tuple[str] = ())[source]

Directory manager for Red’s cogs.

This module allows you to load cogs from multiple directories and even from outside the bot directory. You may also set a directory for downloader to install new cogs to, the default being the cogs/ folder in the root bot directory.

coroutine add_path(path: typing.Union[pathlib.Path, str])[source]

Add a cog path to current list.

This will ignore duplicates. Does have a side effect of removing all invalid paths from the saved path list.

Parameters:path (pathlib.Path or str) – Path to add.
Raises:ValueError – If path does not resolve to an existing directory.
coroutine available_modules() → typing.List[str][source]

Finds the names of all available modules to load.

coroutine find_cog(name: str) → _frozen_importlib.ModuleSpec[source]

Find a cog in the list of available paths.

Parameters:name (str) – Name of the cog to find.
Returns:A module spec to be used for specialized cog loading.
Return type:importlib.machinery.ModuleSpec
Raises:RuntimeError – If there is no cog with the given name.
coroutine install_path() → pathlib.Path[source]

Get the install path for 3rd party cogs.

Returns:The path to the directory where 3rd party cogs are stored.
Return type:pathlib.Path
static invalidate_caches()[source]

Re-evaluate modules in the py cache.

This is an alias for an importlib internal and should be called any time that a new module has been installed to a cog directory.

coroutine paths() → typing.Tuple[pathlib.Path, ...][source]

Get all currently valid path directories.

Returns:All valid cog paths.
Return type:tuple of pathlib.Path
coroutine remove_path(path: typing.Union[pathlib.Path, str]) → typing.Tuple[pathlib.Path, ...][source]

Remove a path from the current paths list.

Parameters:path (pathlib.Path or str) – Path to remove.
Returns:Tuple of new valid paths.
Return type:tuple of pathlib.Path
coroutine set_install_path(path: pathlib.Path) → pathlib.Path[source]

Set the install path for 3rd party cogs.

Note

The bot will not remember your old cog install path which means that all previously installed cogs will no longer be found.

Parameters:path (pathlib.Path) – The new directory for cog installs.
Returns:Absolute path to the new install directory.
Return type:pathlib.Path
Raises:ValueError – If path is not an existing directory.
coroutine set_paths(paths_: typing.List[pathlib.Path])[source]

Set the current paths list.

Parameters:paths (list of pathlib.Path) – List of paths to set.