Cog Manager

class redbot.core.cog_manager.CogManager[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: Union[pathlib.Path, str]) → None[source]

Add a cog path to current list.

This will ignore duplicates.

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

Finds the names of all available modules to load.

coroutine find_cog(name: str) → Optional[_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, if found.
Return type:Optional[importlib.machinery.ModuleSpec]
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() → List[pathlib.Path][source]

Get all currently valid path directories, in order of priority

Returns:A list of paths where cog packages can be found. The install path is highest priority, followed by the user-defined paths, and the core path has the lowest priority.
Return type:List[pathlib.Path]
coroutine remove_path(path: Union[pathlib.Path, str]) → None[source]

Remove a path from the current paths list.

Parameters:path (pathlib.Path or str) – Path to remove.
coroutine set_install_path(path: pathlib.Path) → pathlib.Path[source]

Set the install path for 3rd party cogs.


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_: List[pathlib.Path])[source]

Set the current paths list.

Parameters:paths (list of pathlib.Path) – List of paths to set.
coroutine user_defined_paths() → List[pathlib.Path][source]

Get a list of user-defined cog paths.

All paths will be absolute and unique, in order of priority.

Returns:A list of user-defined paths.
Return type:List[pathlib.Path]