Plugins API Reference#
- class lightbulb.plugins.Plugin(name: str, description: str | None = None, include_datastore: bool = False, default_enabled_guilds: int | Sequence[int] | UndefinedType = UNDEFINED)[source]#
Container class for commands and listeners that can be loaded and unloaded from the bot to allow for hot-swapping of commands.
- Parameters:
name (
str
) – The name of the plugin.description (Optional[
str
]) – Description of the plugin. Defaults toNone
.include_datastore (
bool
) – Whether or not to create aDataStore
instance internally for this plugin.default_enabled_guilds (UndefinedOr[Union[
int
, Sequence[int
]]]) – The guilds to create application commands registered to this plugin in by default. This overridesdefault_enabled_guilds
but is overridden byguilds
.
New in version 2.1.2:
default_enabled_guilds
arg.- add_checks(*checks: t.Union[checks_.Check, checks_._ExclusiveCheck]) None [source]#
Adds one or more checks to the plugin object. These checks will be run for all commands in the plugin.
- Parameters:
*checks (
Check
) – Check object(s) to add to the command.- Returns:
None
- command(cmd_like: commands.base.CommandLike) commands.base.CommandLike [source]#
- command() t.Callable[[commands.base.CommandLike], commands.base.CommandLike]
Adds a
CommandLike
object as a command to the plugin. This method can be used as a first or second order decorator, or called manually with theCommandLike
instance to add as a command.
- create_commands() None [source]#
Creates the command objects implemented by the
CommandLike
objects registered to the plugin.- Returns:
None
- listener(event: Type[Event], listener_func: ListenerT, *, bind: bool = False) ListenerT [source]#
- listener(event: Type[Event], *, bind: bool = False) Callable[[ListenerT], ListenerT]
Adds a listener function to the plugin. This method can be used as a second order decorator, or called manually with the event type and function to add to the plugin as a listener.
- Parameters:
event (Type[
Event
) – Event that the listener is for.- Keyword Arguments:
bind (
bool
) – Whether or not to bind the listener function to the plugin. IfTrue
, the function will be converted into a bound method and so will be called with the plugin as the first argument, and the error event as the second argument. Defaults toFalse
.
- remove_hook(func: RemoveHookT, *, bind: bool = False) RemoveHookT [source]#
- remove_hook(*, bind: bool = False) Callable[[RemoveHookT], RemoveHookT]
Sets the remove hook function for the plugin. This method can be used as a second order decorator, or called manually with the function to set the plugin’s remove hook to. The registered function will be called when the plugin is removed from the bot so may be useful for teardown.
This function will be called after all the members of the plugin (listeners and commands) have already been removed from the bot.
- Keyword Arguments:
bind (
bool
) – Whether or not to bind the remove hook function to the plugin. IfTrue
, the function will be converted into a bound method and so will be called with the plugin as an argument. Defaults toFalse
.
- set_error_handler(func: ErrorHandlerT, *, bind: bool = False) ErrorHandlerT [source]#
- set_error_handler(*, bind: bool = False) Callable[[ErrorHandlerT], ErrorHandlerT]
Sets the error handler function for the plugin. This method can be used as a second order decorator, or called manually with the event type and function to set the plugin’s error handler to.
- Keyword Arguments:
bind (
bool
) – Whether or not to bind the error handler function to the plugin. IfTrue
, the function will be converted into a bound method and so will be called with the plugin as the first argument, and the error event as the second argument. Defaults toFalse
.
- property all_commands: t.List[commands.base.Command]#
List of all created command objects registered to the plugin.
- property d: DataStore#
A
DataStore
instance enabling storage of custom data without subclassing. This will raise aRuntimeError
unless you explicitly specify you want the data storage instance included by passing the kwarginclude_datastore=True
to the constructor.
- default_enabled_guilds: hikari.UndefinedOr[t.Sequence[int]]#
The guilds that application commands registered to this plugin will be created in by default.
- property listeners: Mapping[Type[Event], Collection[Callable[[Event], Coroutine[Any, Any, None]]]]#
Mapping of event type to listeners registered to the plugin
- property raw_commands: t.List[commands.base.CommandLike]#
List of all the CommandLike objects registered to the plugin.