lightbulb.commands.commands

class CommandBase(*args: Any, **kwargs: Any)[source]

Base class that all commands should inherit from. Contains meta information about the command, execution information for each created instance, and various utility methods.

async classmethod as_command_builder(default_locale: Locale, localization_provider: localization.LocalizationProvider) CommandBuilder[source]

Convert the command into a hikari command builder object.

Returns:

The builder object for this command.

Return type:

hikari.api.special_endpoints.CommandBuilder

async classmethod to_command_option(default_locale: Locale, localization_provider: localization.LocalizationProvider) CommandOption[source]

Convert the command into a sub-command command option.

Returns:

The sub-command option for this command.

Return type:

hikari.commands.CommandOption

class CommandData(type: CommandType, name: str, description: str, localize: bool, nsfw: bool, dm_enabled: bool, default_member_permissions: Permissions | UndefinedType, hooks: Sequence[ExecutionHook], options: Mapping[str, OptionData[Any]], invoke_method: str)[source]

Dataclass for storing generic information about the command relevant for its creation and execution.

async as_command_builder(default_locale: Locale, localization_provider: localization.LocalizationProvider) CommandBuilder[source]

Convert the command data into a hikari command builder object.

Returns:

The builder object for this command data.

Return type:

hikari.api.special_endpoints.CommandBuilder

async to_command_option(default_locale: Locale, localization_provider: localization.LocalizationProvider) CommandOption[source]

Convert the command data into a sub-command command option.

Returns:

The sub-command option for this command data.

Return type:

hikari.commands.CommandOption

default_member_permissions: hikari.UndefinedOr[Permissions]

The default permissions required to use the command in a guild. This field is ignored for subcommands.

description: str

The description of the command.

dm_enabled: bool

Whether the command is enabled in direct messages. This field is ignored for subcommands.

hooks: Sequence[ExecutionHook]

Hooks to run prior to the invoke method being executed.

invoke_method: str

The attribute name of the invoke method for the command.

localize: bool

Whether the command name and description should be localized.

name: str

The name of the command.

nsfw: bool

Whether the command is marked as nsfw.

options: Mapping[str, options_.OptionData[t.Any]]

Map of option name to option data for the command options.

parent: Group | SubGroup | None

The group that the command belongs to, or None if not applicable.

property qualified_name: str

The fully qualified name of the command, including the name of any command groups.

If this command - or any parents - has localization enabled then this will instead show the localization keys for the command and its parent groups.

type: CommandType

The type of the command.

class CommandMeta(cls_name: str, bases: tuple[type, ...], attrs: dict[str, Any], **kwargs: Any)[source]

Metaclass for defining application commands.

This metaclass handles the creation of your own application command implementation using the class parameters passed upon class declaration. It is not recommended that you use this metaclass directly - your commands should instead inherit from one of the built-in implementations (SlashCommand, UserCommand, MessageCommand).

Parameters:
  • type – The type of the command that the class implements. This should not be passed manually - it is filled automatically depending on the command implementation class that is subclassed. I.e. subclassing SlashCommand sets this parameter to hikari.CommandType.SLASH.

  • name – The name of the command.

  • description – The description of the command. Only required for slash commands.

  • localize – Whether to localize the command’s name and description. If true, then the name and description arguments will instead be interpreted as localization keys from which the actual name and description will be retrieved. Defaults to False.

  • nsfw – Whether the command should be marked as nsfw. Defaults to False.

  • dm_enabled – Whether the command can be used in direct messages. Defaults to True.

  • default_member_permissions – The default permissions required for a guild member to use the command. If unspecified, all users can use the command by default. Set to hikari.Permissions.NONE to disable for everyone apart from admins.

  • hooks – The hooks to run before the command invocation function is executed. Defaults to an empty set.

class MessageCommand(*args: Any, **kwargs: Any)[source]

Base implementation of a slash command. This should be subclassed in order to create your own message command.

All subclasses must contain a method marked with the lightbulb.commands.execution.invoke decorator.

Parameters:
  • name – The name of the command.

  • localize – Whether to localize the command’s name and description. If true, then the name argument will instead be interpreted as a localization key from which the actual name will be retrieved. Defaults to False.

  • nsfw – Whether the command should be marked as nsfw. Defaults to False.

  • dm_enabled – Whether the command can be used in direct messages. Defaults to True.

  • default_member_permissions – The default permissions required for a guild member to use the command. If unspecified, all users can use the command by default.

  • hooks – The hooks to run before the command invocation function is executed. Defaults to an empty set.

Example

class WordCount(
    lightbulb.MessageCommand,
    name="wordcount",
    description="counts the words in the message",
    ...  # additional parameters
):
    @lightbulb.invoke
    async def invoke(self, ctx: lightbulb.Context):
        await ctx.respond(f"Message has {len(self.target.content.split()} words")
target: Message = <lightbulb.Marker: 'EMPTY'>

The target message that the context menu command was executed on.

class SlashCommand(*args: Any, **kwargs: Any)[source]

Base implementation of a slash command. This should be subclassed in order to create your own slash command.

All subclasses must contain a method marked with the lightbulb.commands.execution.invoke decorator.

Parameters:
  • name – The name of the command.

  • description – The description of the command.

  • localize – Whether to localize the command’s name and description. If true, then the name and description arguments will instead be interpreted as localization keys from which the actual name and description will be retrieved. Defaults to False.

  • nsfw – Whether the command should be marked as nsfw. Defaults to False.

  • dm_enabled – Whether the command can be used in direct messages. Defaults to True.

  • default_member_permissions – The default permissions required for a guild member to use the command. If unspecified, all users can use the command by default.

  • hooks – The hooks to run before the command invocation function is executed. Defaults to an empty set.

Example

class Hello(
    lightbulb.SlashCommand,
    name="hello",
    description="makes the bot say hello",
    ...  # additional parameters
):
    @lightbulb.invoke
    async def invoke(self, ctx: lightbulb.Context):
        await ctx.respond("Hello!")
class UserCommand(*args: Any, **kwargs: Any)[source]

Base implementation of a slash command. This should be subclassed in order to create your own user command.

All subclasses must contain a method marked with the lightbulb.commands.execution.invoke decorator.

Parameters:
  • name – The name of the command.

  • localize – Whether to localize the command’s name and description. If true, then the name argument will instead be interpreted as a localization key from which the actual name will be retrieved. Defaults to False.

  • nsfw – Whether the command should be marked as nsfw. Defaults to False.

  • dm_enabled – Whether the command can be used in direct messages. Defaults to True.

  • default_member_permissions – The default permissions required for a guild member to use the command. If unspecified, all users can use the command by default.

  • hooks – The hooks to run before the command invocation function is executed. Defaults to an empty set.

Example

class UserId(
    lightbulb.SlashCommand,
    name="userid",
    description="gets the ID of the user",
    ...  # additional parameters
):
    @lightbulb.invoke
    async def invoke(self, ctx: lightbulb.Context):
        await ctx.respond(f"ID is {int(self.target.id)}")
target: User = <lightbulb.Marker: 'EMPTY'>

The target user that the context menu command was executed on.