Context API Reference#
Base#
- class lightbulb.context.base.ApplicationContext(app: app_.BotApp, event: hikari.InteractionCreateEvent, command: commands.base.ApplicationCommand)[source]#
- get_channel() Optional[Union[hikari.channels.GuildChannel, hikari.snowflakes.Snowflake]] [source]#
The channel object for the context’s channel ID.
- async respond(*args: Any, delete_after: Optional[Union[float, int]] = None, **kwargs: Any) lightbulb.context.base.ResponseProxy [source]#
Create a response for this context. The first time this method is called, the initial interaction response will be created by calling
create_initial_response
with the response type set toMESSAGE_CREATE
if not otherwise specified.Subsequent calls will instead create followup responses to the interaction by calling
execute
.- Parameters
*args (Any) – Positional arguments passed to
CommandInteraction.create_initial_response
orCommandInteraction.execute
.delete_after (Union[int, float, None]) – The number of seconds to wait before deleting this response.
**kwargs – Keyword arguments passed to
CommandInteraction.create_initial_response
orCommandInteraction.execute
.
- Returns
Proxy wrapping the response of the
respond
call.- Return type
- property author: hikari.users.User#
The author for the context.
- property channel_id: Union[hikari.snowflakes.Snowflake, int]#
The channel ID for the context.
- abstract property command: commands.base.ApplicationCommand#
The root command object that the context is for.
- property event: hikari.events.interaction_events.InteractionCreateEvent#
The event for the context.
- property guild_id: Optional[Union[hikari.snowflakes.Snowflake, int]]#
The guild ID for the context.
- property interaction: hikari.interactions.command_interactions.CommandInteraction#
The interaction that triggered this context. Will be
None
for prefix commands.
- property member: Optional[hikari.guilds.Member]#
The member for the context.
- property resolved: Optional[hikari.interactions.command_interactions.ResolvedOptionData]#
The resolved option data for this context. Will be
None
for prefix commands
- class lightbulb.context.base.Context(app: app_.BotApp)[source]#
Abstract base class for all context types.
- Parameters
app (
BotApp
) – TheBotApp
instance that the context is linked to.
- async delete_last_response() None [source]#
Delete the most recently send response. Shortcut for
hikari.messages.Message.delete
.- Returns
None
- async edit_last_response(*args: Any, **kwargs: Any) Optional[hikari.messages.Message] [source]#
Edit the most recently sent response. Shortcut for
hikari.messages.Message.edit
.- Parameters
*args – Args passed to
hikari.messages.Message.edit
.**kwargs – Kwargs passed to
hikari.messages.Message.edit
.
- Returns
- New message after edit, or
None
if no responses have been sent for the context yet.
- New message after edit, or
- Return type
Optional[
Message
]
- abstract get_channel() Optional[Union[hikari.channels.GuildChannel, hikari.snowflakes.Snowflake]] [source]#
The channel object for the context’s channel ID.
- get_guild() Optional[hikari.guilds.Guild] [source]#
The guild object for the context’s guild ID.
- abstract async respond(response_type: hikari.interactions.base_interactions.ResponseType, content: Union[Any, hikari.undefined.UndefinedType] = hikari.UNDEFINED, delete_after: Optional[Union[int, float]] = None, *, attachment: Union[Resource[Any], os.PathLike[str], str, bytes, bytearray, memoryview, _io.BytesIO, _io.StringIO, hikari.undefined.UndefinedType] = 'hikari.UNDEFINED', attachments: Union[Sequence[Union[Resource[Any], os.PathLike[str], str, bytes, bytearray, memoryview, _io.BytesIO, _io.StringIO]], hikari.undefined.UndefinedType] = 'hikari.UNDEFINED', component: Union[hikari.api.special_endpoints.ComponentBuilder, hikari.undefined.UndefinedType] = 'hikari.UNDEFINED', components: Union[Sequence[hikari.api.special_endpoints.ComponentBuilder], hikari.undefined.UndefinedType] = 'hikari.UNDEFINED', embed: Union[hikari.embeds.Embed, hikari.undefined.UndefinedType] = 'hikari.UNDEFINED', embeds: Union[Sequence[hikari.embeds.Embed], hikari.undefined.UndefinedType] = 'hikari.UNDEFINED', flags: Union[int, hikari.messages.MessageFlag, hikari.undefined.UndefinedType] = 'hikari.UNDEFINED', tts: Union[bool, hikari.undefined.UndefinedType] = 'hikari.UNDEFINED', nonce: Union[str, hikari.undefined.UndefinedType] = 'hikari.UNDEFINED', reply: Union[hikari.messages.PartialMessage, hikari.snowflakes.Snowflake, int, hikari.undefined.UndefinedType] = 'hikari.UNDEFINED', mentions_everyone: Union[bool, hikari.undefined.UndefinedType] = 'hikari.UNDEFINED', mentions_reply: Union[bool, hikari.undefined.UndefinedType] = 'hikari.UNDEFINED', user_mentions: Union[Sequence[Union[hikari.users.PartialUser, hikari.snowflakes.Snowflake, int]], bool, hikari.undefined.UndefinedType] = 'hikari.UNDEFINED', role_mentions: Union[Sequence[Union[hikari.guilds.PartialRole, hikari.snowflakes.Snowflake, int]], bool, hikari.undefined.UndefinedType] = 'hikari.UNDEFINED') lightbulb.context.base.ResponseProxy [source]#
- abstract async respond(content: Union[Any, hikari.undefined.UndefinedType] = hikari.UNDEFINED, delete_after: Optional[Union[int, float]] = None, *, attachment: Union[Resource[Any], os.PathLike[str], str, bytes, bytearray, memoryview, _io.BytesIO, _io.StringIO, hikari.undefined.UndefinedType] = 'hikari.UNDEFINED', attachments: Union[Sequence[Union[Resource[Any], os.PathLike[str], str, bytes, bytearray, memoryview, _io.BytesIO, _io.StringIO]], hikari.undefined.UndefinedType] = 'hikari.UNDEFINED', component: Union[hikari.api.special_endpoints.ComponentBuilder, hikari.undefined.UndefinedType] = 'hikari.UNDEFINED', components: Union[Sequence[hikari.api.special_endpoints.ComponentBuilder], hikari.undefined.UndefinedType] = 'hikari.UNDEFINED', embed: Union[hikari.embeds.Embed, hikari.undefined.UndefinedType] = 'hikari.UNDEFINED', embeds: Union[Sequence[hikari.embeds.Embed], hikari.undefined.UndefinedType] = 'hikari.UNDEFINED', flags: Union[int, hikari.messages.MessageFlag, hikari.undefined.UndefinedType] = 'hikari.UNDEFINED', tts: Union[bool, hikari.undefined.UndefinedType] = 'hikari.UNDEFINED', nonce: Union[str, hikari.undefined.UndefinedType] = 'hikari.UNDEFINED', reply: Union[hikari.messages.PartialMessage, hikari.snowflakes.Snowflake, int, hikari.undefined.UndefinedType] = 'hikari.UNDEFINED', mentions_everyone: Union[bool, hikari.undefined.UndefinedType] = 'hikari.UNDEFINED', mentions_reply: Union[bool, hikari.undefined.UndefinedType] = 'hikari.UNDEFINED', user_mentions: Union[Sequence[Union[hikari.users.PartialUser, hikari.snowflakes.Snowflake, int]], bool, hikari.undefined.UndefinedType] = 'hikari.UNDEFINED', role_mentions: Union[Sequence[Union[hikari.guilds.PartialRole, hikari.snowflakes.Snowflake, int]], bool, hikari.undefined.UndefinedType] = 'hikari.UNDEFINED') lightbulb.context.base.ResponseProxy
Create a response to this context.
- property app: app_.BotApp#
The
BotApp
instance the context is linked to.
- abstract property author: hikari.users.User#
The author for the context.
- abstract property channel_id: Union[hikari.snowflakes.Snowflake, int]#
The channel ID for the context.
- abstract property command: t.Optional[commands.base.Command]#
The root command object that the context is for.
- abstract property event: Union[hikari.events.message_events.MessageCreateEvent, hikari.events.interaction_events.InteractionCreateEvent]#
The event for the context.
- abstract property guild_id: Optional[Union[hikari.snowflakes.Snowflake, int]]#
The guild ID for the context.
- property interaction: Optional[hikari.interactions.command_interactions.CommandInteraction]#
The interaction that triggered this context. Will be
None
for prefix commands.
- property invoked: t.Optional[commands.base.Command]#
The command or subcommand that was invoked in this context.
- abstract property member: Optional[hikari.guilds.Member]#
The member for the context.
- property options: lightbulb.context.base.OptionsProxy#
OptionsProxy
wrapping the options that the user invoked the command with.
- property previous_response: Optional[lightbulb.context.base.ResponseProxy]#
The last response sent for this context.
- property raw_options: Dict[str, Any]#
Dictionary of
str
option name to option value that the user invoked the command with.
- property resolved: Optional[hikari.interactions.command_interactions.ResolvedOptionData]#
The resolved option data for this context. Will be
None
for prefix commands
- property responses: List[lightbulb.context.base.ResponseProxy]#
List of all previous responses sent for this context.
- property user: hikari.users.User#
The user for the context. Alias for
author
.
- class lightbulb.context.base.OptionsProxy(options: Dict[str, Any])[source]#
Proxy for the options that the command was invoked with allowing access using dot notation instead of dictionary lookup.
- Parameters
options (Dict[
str
, Any]) – Options to act as a proxy for.
- class lightbulb.context.base.ResponseProxy(message: Optional[hikari.messages.Message] = None, fetcher: Optional[Callable[[], Coroutine[Any, Any, hikari.messages.Message]]] = None, editor: Optional[Callable[[lightbulb.context.base.ResponseProxy], Coroutine[Any, Any, hikari.messages.Message]]] = None, editable: bool = True, deleteable: bool = True)[source]#
Proxy for context responses. Allows fetching of the message created from the response lazily instead of a follow-up request being made immediately.
- async delete() None [source]#
Deletes the message that this object is proxying.
- Returns
None
- Raises
UnsupportedResponseOperation – This response cannot be deleted (for ephemeral interaction responses).
- async edit(*args: Any, **kwargs: Any) hikari.messages.Message [source]#
Edits the message that this object is proxying. Shortcut for
hikari.messages.Message.edit
.- Parameters
*args – Args passed in to
hikari.messages.Message.edit
**kwargs – Kwargs passed in to
hikari.messages.Message.edit
- Returns
New message after edit.
- Return type
- Raises
UnsupportedResponseOperation – This response cannot be edited (for ephemeral interaction followup responses).
- async message() hikari.messages.Message [source]#
Fetches and/or returns the created message from the context response.
- Returns
The response’s created message.
- Return type
Prefix Context#
- class lightbulb.context.prefix.PrefixContext(app: app_.BotApp, event: hikari.MessageCreateEvent, command: t.Optional[commands.prefix.PrefixCommand], invoked_with: str, prefix: str)[source]#
Bases:
lightbulb.context.base.Context
An implementation of
Context
for prefix commands.- Parameters
app (
BotApp
) – TheBotApp
instance that the context is linked to.event (
MessageCreateEvent
) – The event to create the context from.command (Optional[
PrefixCommand
]) – The command that the context is for, orNone
if no command could be resolved.invoked_with (
str
) – The name or alias that the command was invoked with.prefix (
str
) – The prefix that was used in this context.
- get_channel() Optional[Union[hikari.channels.GuildChannel, hikari.snowflakes.Snowflake]] [source]#
The channel object for the context’s channel ID.
- async respond(*args: Any, delete_after: Optional[Union[float, int]] = None, **kwargs: Any) lightbulb.context.base.ResponseProxy [source]#
Create a response for this context. This method directly calls
respond
. You should note that it is not possible to send ephemeral messages as responses to prefix commands. All message flags will be removed before the call torespond
.
- property author: hikari.users.User#
The author for the context.
- property channel_id: Union[hikari.snowflakes.Snowflake, int]#
The channel ID for the context.
- property command: t.Optional[commands.prefix.PrefixCommand]#
The root command object that the context is for.
- property event: hikari.events.message_events.MessageCreateEvent#
The event for the context.
- property guild_id: Optional[Union[hikari.snowflakes.Snowflake, int]]#
The guild ID for the context.
- property member: Optional[hikari.guilds.Member]#
The member for the context.
Slash Context#
- class lightbulb.context.slash.SlashContext(app: app_.BotApp, event: hikari.InteractionCreateEvent, command: commands.slash.SlashCommand)[source]#
Bases:
lightbulb.context.base.ApplicationContext
An implementation of
Context
for slash commands.- Parameters
app (
BotApp
) – TheBotApp
instance that the context is linked to.event (
InteractionCreateEvent
) – The event to create the context from.command (
SlashCommand
) – The command that the context is for.
- property command: lightbulb.commands.slash.SlashCommand#
The root command object that the context is for.
Message Context#
- class lightbulb.context.message.MessageContext(app: app_.BotApp, event: hikari.InteractionCreateEvent, command: commands.message.MessageCommand)[source]#
Bases:
lightbulb.context.base.ApplicationContext
An implementation of
Context
for message context menu commands.- Parameters
app (
BotApp
) – TheBotApp
instance that the context is linked to.event (
InteractionCreateEvent
) – The event to create the context from.command (
MessageCommand
) – The command that the context is for.
Note that the target message that this command was invoked on will always be stored as the option
target
.Example
@lightbulb.command("id", "Gets the ID of the selected message") @lightbulb.implements(lightbulb.MessageCommand) async def get_message_id(ctx: lightbulb.MessageContext) -> None: await ctx.respond(ctx.options.target.id)
- property command: lightbulb.commands.message.MessageCommand#
The root command object that the context is for.
User Context#
- class lightbulb.context.user.UserContext(app: app_.BotApp, event: hikari.InteractionCreateEvent, command: commands.user.UserCommand)[source]#
Bases:
lightbulb.context.base.ApplicationContext
An implementation of
Context
for user context menu commands.- Parameters
app (
BotApp
) – TheBotApp
instance that the context is linked to.event (
InteractionCreateEvent
) – The event to create the context from.command (
UserCommand
) – The command that the context is for.
Note that the target user that this command was invoked on will always be stored as the option
target
.Example
@lightbulb.command("id", "Gets the ID of the selected user") @lightbulb.implements(lightbulb.UserCommand) async def get_user_id(ctx: lightbulb.UserContext) -> None: await ctx.respond(ctx.options.target.id)
- property command: lightbulb.commands.user.UserCommand#
The root command object that the context is for.