Decorators API Reference#

lightbulb.decorators.add_checks(*cmd_checks: t.Union[checks_.Check, checks_._ExclusiveCheck]) t.Callable[[commands.base.CommandLike], commands.base.CommandLike][source]#

Second order decorator that adds one or more checks to the decorated CommandLike object.

Parameters

*cmd_checks (Check) – Check object(s) to add to the command.

lightbulb.decorators.add_cooldown(length: float, uses: int, bucket: Type[lightbulb.buckets.Bucket]) Callable[[lightbulb.commands.base.CommandLike], lightbulb.commands.base.CommandLike][source]#
lightbulb.decorators.add_cooldown(*, callback: t.Callable[[context.base.Context], t.Union[buckets.Bucket, t.Coroutine[t.Any, t.Any, buckets.Bucket]]]) Callable[[lightbulb.commands.base.CommandLike], lightbulb.commands.base.CommandLike]

Second order decorator that sets the cooldown manager for a command.

Parameters
  • length (float) – The length in seconds of the cooldown timer.

  • uses (int) – The number of command invocations before the cooldown will be triggered.

  • bucket (Type[Bucket]) – The bucket to use for cooldowns.

Keyword Arguments
  • callback (Callable[[Bucket, Coroutine[Any, Any, Bucket]]]) – Callable that takes the context the command was invoked under and returns the appropriate bucket object to use for cooldowns in the context.

  • cls (Type[CooldownManager]) – The cooldown manager class to use. Defaults to CooldownManager.

lightbulb.decorators.check_exempt(predicate: t.Callable[[context.base.Context], t.Union[bool, t.Coroutine[t.Any, t.Any, bool]]]) t.Callable[[commands.base.CommandLike], commands.base.CommandLike][source]#

Second order decorator which allows all checks to be bypassed if the predicate conditions are met. Predicate can be a synchronous or asynchronous function but must take a single argument - context - and must return a boolean - True if checks should be bypassed or False if not.

Parameters

predicate (Callable[[Context], Union[bool, Coroutine[Any, Any, bool]]) – The function to call to check if the checks should be bypassed for the given context.

lightbulb.decorators.command(name: str, description: str, *, cls: typing.Type[lightbulb.commands.base.CommandLike] = <class 'lightbulb.commands.base.CommandLike'>, **kwargs: typing.Any) Callable[[lightbulb.decorators.CommandCallbackT], lightbulb.commands.base.CommandLike][source]#

Second order decorator that converts the decorated function into a CommandLike object.

Parameters
  • name (str) – The name of the command .

  • description (str) – The description of the command.

Keyword Arguments
  • error_handler (Optional[ListenerT]) – The function to register as the command’s error handler. Defaults to None. This can also be set with the set_error_handler decorator.

  • aliases (Sequence[str]) – Aliases for the command. This will only affect prefix commands. Defaults to an empty list.

  • guilds (Sequence[int]) – The guilds that the command will be created in. This will only affect application commands. Defaults to an empty list.

  • parser (BaseParser) – The argument parser to use for prefix commands. Defaults to Parser.

  • auto_defer (bool) – Whether or not to automatically defer the response when the command is invoked. If True, the bot will send an initial response of type DEFERRED_MESSAGE_CREATE for interactions, and for prefix commands, typing will be triggered in the invocation channel.

  • ephemeral (bool) – Whether or not to send responses from the invocation of this command as ephemeral by default. If True then all responses from the command will use the flag hikari.MessageFlags.EPHEMERAL. This will not affect prefix commands as responses from prefix commands cannot be ephemeral.

  • hidden (bool) – Whether or not to hide the command from the help command. Defaults to False.

  • inherit_checks (bool) – Whether or not the command should inherit checks from the parent group. Only affects subcommands. Defaults to False.

  • pass_options (bool) – Whether the command will have its options passed as keyword arguments when invoked.

  • cls (Type[CommandLike]) – CommandLike class to instantiate from this decorator. Defaults to CommandLike.

lightbulb.decorators.implements(*command_types: Type[lightbulb.commands.base.Command]) Callable[[lightbulb.decorators.CommandCallbackT], lightbulb.decorators.CommandCallbackT][source]#

Second order decorator that defines the command types that a given callback function will implement.

Parameters

*command_types (Type[Command]) – Command types that the function will implement.

lightbulb.decorators.option(name: str, description: str, type: typing.Any = <class 'str'>, *, required: typing.Union[bool, hikari.undefined.UndefinedType] = UNDEFINED, choices: typing.Optional[typing.Sequence[typing.Union[str, int, float, hikari.commands.CommandChoice]]] = None, channel_types: typing.Optional[typing.Sequence[hikari.channels.ChannelType]] = None, default: typing.Union[typing.Any, hikari.undefined.UndefinedType] = UNDEFINED, modifier: lightbulb.commands.base.OptionModifier = OptionModifier.NONE, min_value: typing.Optional[typing.Union[float, int]] = None, max_value: typing.Optional[typing.Union[float, int]] = None, autocomplete: typing.Union[bool, typing.Callable[[hikari.interactions.command_interactions.CommandInteractionOption, hikari.interactions.command_interactions.AutocompleteInteraction], typing.Coroutine[typing.Any, typing.Any, typing.Union[str, hikari.commands.CommandChoice, typing.Sequence[typing.Union[str, hikari.commands.CommandChoice]]]]]] = False, cls: typing.Type[lightbulb.commands.base.OptionLike] = <class 'lightbulb.commands.base.OptionLike'>, **kwargs: typing.Any) Callable[[lightbulb.commands.base.CommandLike], lightbulb.commands.base.CommandLike][source]#

Second order decorator that adds an option to the decorated CommandLike object.

Parameters
  • name (str) – The name of the option.

  • description (str) – The description of the option.

  • type (Any) – The type of the option. This will be used as the converter for prefix commands.

Keyword Arguments
  • required (UndefinedOr[bool]) – Whether this option is required. This will be inferred from whether a default value for the option was specified if not otherwise specified.

  • choices (Optional[Sequence[Union[str, int, float, CommandChoice]]]) – The choices for the option. This will only affect slash commands. Defaults to None.

  • channel_types (Optional[Sequence[hikari.channels.ChannelType]]) – The channel types allowed for the option. This will only affect slash commands. Defaults to None.

  • default (UndefinedOr[Any]) – The default value for the option. Defaults to UNDEFINED.

  • modifier (OptionModifier) – Modifier controlling how the option should be parsed. Defaults to OptionModifier.NONE.

  • min_value (Optional[Union[float, int]]) – The minimum value permitted for this option (inclusive). Only available if the option type is numeric (integer or float). Defaults to None.

  • max_value (Optional[Union[float, int]]) – The maximum value permitted for this option (inclusive). Only available if the option type is numeric (integer or float). Defaults to None.

  • autocomplete (Union[bool, AutocompleteCallbackT]) – Boolean representing whether the option will use autocomplete or the callback to use for autocomplete for this option. This will only affect slash commands. Defaults to False.

  • cls (Type[OptionLike]) – OptionLike class to instantiate from this decorator. Defaults to OptionLike.

lightbulb.decorators.set_help(text: t.Optional[t.Union[str, t.Callable[[commands.base.Command, context.base.Context], str]]] = None, *, docstring: bool = False) t.Callable[[commands.base.CommandLike], commands.base.CommandLike][source]#

Second order decorator that defines the long help text for a command, or how the long help text should be retrieved. If text is provided then it will override the value for docstring.

Parameters

text (Union[Callable[[Command, Context], str], str]) – The long help text for the command, or a synchronous function called with the Command object to get help text for and the Context that the help text should be retrieved for. If this is not provided, then you must pass the kwarg docstring=True.

Keyword Arguments

docstring (bool) – Whether the command help text should be extracted from the command’s docstring. If this is False (default) then a value must be provided for the text arg.

lightbulb.decorators.set_max_concurrency(uses: int, bucket: Type[lightbulb.buckets.Bucket]) Callable[[lightbulb.commands.base.CommandLike], lightbulb.commands.base.CommandLike][source]#

Second order decorator that defines the max concurrency limit for a command.

Parameters
  • uses (int) – The maximum number of uses of the command that can be executing concurrently before a MaxConcurrencyLimitReached will be raised upon invocation.

  • bucket (Type[Bucket]) – Bucket that command max concurrency will be processed under.