lightbulb.loaders

class lightbulb.loaders.Loadable[source]

Abstract class containing the logic required to add and remove a feature from a client instance.

abstract async load(client: client_.Client) None[source]

Add the feature to the client instance.

Parameters:

client (Client) – The client instance to add the feature to.

Returns:

None

async unload(client: client_.Client) None[source]

Remove the feature from the client instance.

Parameters:

client (Client) – The client instance to remove the feature from.

Returns:

None

class lightbulb.loaders.Loader[source]

Class used for loading features into the client from extensions.

async add_to_client(client: client_.Client) None[source]

Add the features contained within this loader to the given client.

Parameters:

client (Client) – The client to add this loader’s features to.

Returns:

None

command(*, guilds: Sequence[Snowflake | int] | None = None) Callable[[CommandOrGroupT], CommandOrGroupT][source]
command(command: CommandOrGroupT, *, guilds: Sequence[Snowflake | int] | None = None) CommandOrGroupT

Register a command or group with this loader. Optionally, a sequence of guild ids can be provided to make the commands created in specific guilds only - overriding the value for default enabled guilds.

This method can be used as a function, or a first or second order decorator.

Parameters:
  • command (Union [ Type [ Group ]) – The command class or command group to register with the client.

  • guilds (Optional [ Sequence [ Snowflakeish ]]) – The guilds to create the command or group in. If set to None, then this will fall back to the default enabled guilds. To override default enabled guilds and make the command or group global, this should be set to an empty sequence.

Returns:

The registered command or group, unchanged.

Example

loader = lightbulb.Loader()

# valid
@loader.register
# also valid
@loader.register(guilds=[...])
class Example(
    lightbulb.SlashCommand,
    ...
):
    ...

# also valid
loader.register(Example, guilds=[...])
error_handler(*, priority: int = 0) Callable[[ErrorHandlerT], ErrorHandlerT][source]
error_handler(func: ErrorHandlerT, *, priority: int = 0) ErrorHandlerT

Register an error handler function to call when an ExecutionPipeline fails. Also enables dependency injection for the error handler function.

The function must take the exception as its first argument, which will be an instance of ExecutionPipelineFailedException. The function must return a boolean indicating whether the exception was successfully handled. Non-boolean return values will be cast to booleans.

Parameters:
  • func – The function to register as a command error handler.

  • priority (int) – The priority that this handler should be registered at. Higher priority handlers will be executed first.

listener(event_type: EventT) Callable[[Callable[[Concatenate[EventT, ...]], Awaitable[None]]], Callable[[EventT], Awaitable[None]]][source]

Decorator to register a listener with this loader. Also enables dependency injection on the listener callback.

If an hikari.api.event_manager.EventManager instance is not available through dependency injection then adding this loader to the client will fail at runtime.

Parameters:

event_type (Type [ hikari.Event ]) – The event class for the listener to listen to.

Example

loader = lightbulb.Loader()

@loader.listener(hikari.MessageCreateEvent)
async def message_create_listener(event: hikari.MessageCreateEvent) -> None:
    ...
async remove_from_client(client: client_.Client) None[source]

Remove the features contained within this loader from the given client. If any single loadable’s unload method raises an exception then the remaining loadables will still be unloaded.

Parameters:

client (Client) – The client to remove this loader’s features from.

Returns:

None