lightbulb.commands.commands

class lightbulb.commands.commands.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: hikari.Locale, localization_provider: localization.LocalizationProviderT) hikari.api.CommandBuilder[source]

Convert the command into a hikari command builder object.

Returns:

The builder object for this command.

Return type:

hikari.api.CommandBuilder

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

Convert the command into a sub-command command option.

Returns:

The sub-command option for this command.

Return type:

hikari.CommandOption

class lightbulb.commands.commands.CommandData(type: CommandType, name: str, description: str, localize: bool, nsfw: bool, dm_enabled: bool, default_member_permissions: Permissions | UndefinedType, hooks: Set[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: hikari.Locale, localization_provider: localization.LocalizationProviderT) hikari.api.CommandBuilder[source]

Convert the command data into a hikari command builder object.

Returns:

The builder object for this command data.

Return type:

hikari.api.CommandBuilder

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

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

Returns:

The sub-command option for this command data.

Return type:

hikari.CommandOption

default_member_permissions: hikari.UndefinedOr[hikari.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: t.Set[execution.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: t.Mapping[str, options_.OptionData[t.Any]]

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

parent: groups.Group | groups.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.

type: hikari.CommandType

The type of the command.

class lightbulb.commands.commands.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 (hikari.CommandType) – 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 (str, required) – The name of the command.

  • description (str, optional) – The description of the command. Only required for slash commands.

  • localize (bool, optional) – 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 (bool, optional) – Whether the command should be marked as nsfw. Defaults to False.

  • dm_enabled (bool, optional) – Whether the command can be used in direct messages. Defaults to True.

  • default_member_permissions (hikari.Permissions, optional) – 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 (Sequence [ ExecutionHook ], optional) – The hooks to run before the command invocation function is executed. Defaults to an empty set.

class lightbulb.commands.commands.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 (str, required) – The name of the command.

  • localize (bool, optional) – 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 (bool, optional) – Whether the command should be marked as nsfw. Defaults to False.

  • dm_enabled (bool, optional) – Whether the command can be used in direct messages. Defaults to True.

  • default_member_permissions (hikari.Permissions, optional) – 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 (Sequence [ ExecutionHook ], optional) – 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: hikari.Message = Message(id=0, channel_id=0, guild_id=None, author=<lightbulb.utils._EmptyUser object>, flags=<MessageFlag.NONE: 0>)

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

class lightbulb.commands.commands.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 (str, required) – The name of the command.

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

  • localize (bool, optional) – 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 (bool, optional) – Whether the command should be marked as nsfw. Defaults to False.

  • dm_enabled (bool, optional) – Whether the command can be used in direct messages. Defaults to True.

  • default_member_permissions (hikari.Permissions, optional) – 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 (Sequence [ ExecutionHook ], optional) – 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 lightbulb.commands.commands.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 (str, required) – The name of the command.

  • localize (bool, optional) – 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 (bool, optional) – Whether the command should be marked as nsfw. Defaults to False.

  • dm_enabled (bool, optional) – Whether the command can be used in direct messages. Defaults to True.

  • default_member_permissions (hikari.Permissions, optional) – 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 (Sequence [ ExecutionHook ], optional) – 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: hikari.User = Message(id=0, channel_id=0, guild_id=None, author=<lightbulb.utils._EmptyUser object>, flags=<MessageFlag.NONE: 0>)

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