lightbulb.loaders¶
- class lightbulb.loaders.Loadable[source]¶
Abstract class containing the logic required to add and remove a feature from a client instance.
- 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.
- 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 toNone
, 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: ...