Skip to content

Plugin

Plugin #

Plugin(
    *,
    command_hooks: list[CommandHookCallbackT] | None = None,
    command_after_hooks: list[CommandHookCallbackT]
    | None = None,
    event_hooks: list[EventHookCallbackT[Event]]
    | None = None,
    event_after_hooks: list[EventHookCallbackT[Event]]
    | None = None
)

Bases: Generic[BotT, ModelT]

A plugin object to be used in a plugin file.

Example#
import hikari
import crescent

plugin = crescent.Plugin[hikari.GatewayBot, None]()

You can load this file with PluginManager.load

PluginManager #

PluginManager(client: Client)

A class that allows you to load and unload plugins. You should not construct this class yourself. It will be provided to you as the clients.plugins property when you construct a Client object.

load #

load(
    path: str, refresh: bool = False, strict: bool = True
) -> Plugin[Any, Any] | None

Load a plugin from the module path.

import crescent

bot = crescent.Bot(token=...)

bot.plugins.load("folder.plugin")
PARAMETER DESCRIPTION
path

The module path for the plugin.

TYPE: str

refresh

Whether or not to reload the plugin and the plugin's module.

TYPE: bool DEFAULT: False

strict

If false, the function will not error when module file does not have a plugin variable.

TYPE: bool DEFAULT: True

load_folder #

load_folder(
    path: str, refresh: bool = False, strict: bool = True
) -> list[Plugin[Any, Any]]

Loads plugins from a folder.

import crescent
import hikari

bot = hikari.GatewayBot(token=...)
client = crescent.Client(bot)

client.plugins.load("project.plugin_folder")

If a file is attempted to be loaded that does not have a plugin variable, a ValueError will be raised. Files who's names start with an underscore will not be loaded.

PARAMETER DESCRIPTION
path

The path to the folder that contains the plugins.

TYPE: str

refresh

Whether or not to reload the plugin and the plugin's module.

TYPE: bool DEFAULT: False

strict

If false, the function will not error when a file does not have a plugin variable.

TYPE: bool DEFAULT: True

Returns: A list of plugins that were loaded.

unload #

unload(path: str) -> None

Unload a plugin.

PARAMETER DESCRIPTION
path

The module path for the plugin.

TYPE: str

unload_all #

unload_all() -> None

Unload all of the plugins that are currently loaded.