Cog Manager

class redbot.core.cog_manager.CogManager[source]

Bases: object

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.

await add_path(path)[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.
await available_modules()[source]

Finds the names of all available modules to load.

await find_cog(name)[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]
await install_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
staticmethod 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.

await paths()[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]
await remove_path(path)[source]

Remove a path from the current paths list.

Parameters:path (pathlib.Path or str) – Path to remove.
await set_install_path(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.
await set_paths(paths_)[source]

Set the current paths list.

Parameters:paths_ (list of pathlib.Path) – List of paths to set.
await user_defined_paths()[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]