lightbulb.components.menus¶
- class ChannelSelect(custom_id: str, placeholder: hikari.UndefinedOr[str], min_values: int, max_values: int, disabled: bool, callback: ComponentCallback, channel_types: hikari.UndefinedOr[Sequence[ChannelType]])[source]¶
Class representing a select menu with channel options.
- add_to_row(row: MessageActionRowBuilder) → MessageActionRowBuilder[source]¶
Add this component to the given action row builder, and return the updated builder.
- Parameters:
row – The row to add the component to.
- Returns:
The updated builder.
- callback: ComponentCallback¶
The callback method to call when the select menu is submitted.
- channel_types: hikari.UndefinedOr[Sequence[ChannelType]]¶
Channel types permitted to be shown as options.
- class InteractiveButton(style: ButtonStyle, custom_id: str, label: hikari.UndefinedOr[str], emoji: hikari.UndefinedOr[Emojiish], disabled: bool, callback: ComponentCallback)[source]¶
Class representing an interactive button.
- add_to_row(row: MessageActionRowBuilder) → MessageActionRowBuilder[source]¶
Add this component to the given action row builder, and return the updated builder.
- Parameters:
row – The row to add the component to.
- Returns:
The updated builder.
- callback: ComponentCallback¶
The callback method to call when the button is pressed.
- emoji: hikari.UndefinedOr[Emojiish]¶
The emoji for the button.
- style: ButtonStyle¶
The style of the button.
- class LinkButton(url: str, label: str | UndefinedType, emoji: Snowflake | int | str | Emoji | UndefinedType, disabled: bool)[source]¶
Dataclass representing a link button.
- add_to_row(row: MessageActionRowBuilder) → MessageActionRowBuilder[source]¶
Add this component to the given action row builder, and return the updated builder.
- Parameters:
row – The row to add the component to.
- Returns:
The updated builder.
- label: str | UndefinedType¶
The label for the button.
- class MentionableSelect(custom_id: str, placeholder: hikari.UndefinedOr[str], min_values: int, max_values: int, disabled: bool, callback: ComponentCallback)[source]¶
Class representing a select menu with snowflake options.
- add_to_row(row: MessageActionRowBuilder) → MessageActionRowBuilder[source]¶
Add this component to the given action row builder, and return the updated builder.
- Parameters:
row – The row to add the component to.
- Returns:
The updated builder.
- callback: ComponentCallback¶
The callback method to call when the select menu is submitted.
- class Menu[source]¶
Class representing a component menu.
- add(component: BaseComponentT) → BaseComponentT¶
Adds the given component to the container.
- Parameters:
component – The component to add.
- Returns:
The added component.
- add_channel_select(on_select: ComponentCallback, *, custom_id: hikari.UndefinedOr[str] = UNDEFINED, placeholder: hikari.UndefinedOr[str] = UNDEFINED, min_values: int = 1, max_values: int = 1, disabled: bool = False, channel_types: hikari.UndefinedOr[Sequence[ChannelType]] = UNDEFINED) → ChannelSelect[source]¶
Add a channel select menu to this menu.
- Parameters:
on_select – The asynchronous function to call when the select menu is submitted.
custom_id – The custom ID for the select menu. Only specify this when you are creating a persistent menu. If unspecified, one will be generated for you.
placeholder – The placeholder string for the select menu.
min_values – The minimum number of values that can be selected.
max_values – The maximum number of values that can be selected.
disabled – Whether the select menu is disabled.
channel_types – The channel types allowed to be selected.
- Returns:
The created select menu.
- add_interactive_button(style: ButtonStyle, on_press: ComponentCallback, *, custom_id: hikari.UndefinedOr[str] = UNDEFINED, label: hikari.UndefinedOr[str] = UNDEFINED, emoji: hikari.UndefinedOr[hikari.Snowflakeish | str | Emoji] = UNDEFINED, disabled: bool = False) → InteractiveButton[source]¶
Add an interactive button to this menu.
- Parameters:
style – The style of the button.
on_press – The asynchronous function to call when the button is pressed.
custom_id – The custom ID for the button. Only specify this when you are creating a persistent menu. If unspecified, one will be generated for you.
label – The label for the button.
emoji – The emoji for the button.
disabled – Whether the button is disabled.
- Returns:
The created button.
- Raises:
ValueError – When neither
label
noremoji
are specified.
- add_link_button(url: str, *, label: str | UndefinedType = UNDEFINED, emoji: Snowflake | int | str | Emoji | UndefinedType = UNDEFINED, disabled: bool = False) → LinkButton[source]¶
Add a link button to this menu.
- Parameters:
url – The url the button should link to.
label – The label for the button.
emoji – The emoji for the button.
disabled – Whether the button is disabled.
- Returns:
The created button.
- Raises:
ValueError – When neither
label
noremoji
are specified.
- add_mentionable_select(on_select: ComponentCallback, *, custom_id: hikari.UndefinedOr[str] = UNDEFINED, placeholder: hikari.UndefinedOr[str] = UNDEFINED, min_values: int = 1, max_values: int = 1, disabled: bool = False) → MentionableSelect[source]¶
Add a ‘mentionable object’ select menu to this menu.
- Parameters:
on_select – The asynchronous function to call when the select menu is submitted.
custom_id – The custom ID for the select menu. Only specify this when you are creating a persistent menu. If unspecified, one will be generated for you.
placeholder – The placeholder string for the select menu.
min_values – The minimum number of values that can be selected.
max_values – The maximum number of values that can be selected.
disabled – Whether the select menu is disabled.
- Returns:
The created select menu.
- add_role_select(on_select: ComponentCallback, *, custom_id: hikari.UndefinedOr[str] = UNDEFINED, placeholder: hikari.UndefinedOr[str] = UNDEFINED, min_values: int = 1, max_values: int = 1, disabled: bool = False) → RoleSelect[source]¶
Add a role select menu to this menu.
- Parameters:
on_select – The asynchronous function to call when the select menu is submitted.
custom_id – The custom ID for the select menu. Only specify this when you are creating a persistent menu. If unspecified, one will be generated for you.
placeholder – The placeholder string for the select menu.
min_values – The minimum number of values that can be selected.
max_values – The maximum number of values that can be selected.
disabled – Whether the select menu is disabled.
- Returns:
The created select menu.
- add_text_select(options: ValidSelectOptions, on_select: ComponentCallback, *, custom_id: hikari.UndefinedOr[str] = UNDEFINED, placeholder: hikari.UndefinedOr[str] = UNDEFINED, min_values: int = 1, max_values: int = 1, disabled: bool = False) → TextSelect[source]¶
Add a text select menu to this menu.
- Parameters:
options – The options for the select menu.
on_select – The asynchronous function to call when the select menu is submitted.
custom_id – The custom ID for the select menu. Only specify this when you are creating a persistent menu. If unspecified, one will be generated for you.
placeholder – The placeholder string for the select menu.
min_values – The minimum number of values that can be selected.
max_values – The maximum number of values that can be selected.
disabled – Whether the select menu is disabled.
- Returns:
The created select menu.
- add_user_select(on_select: ComponentCallback, *, custom_id: hikari.UndefinedOr[str] = UNDEFINED, placeholder: hikari.UndefinedOr[str] = UNDEFINED, min_values: int = 1, max_values: int = 1, disabled: bool = False) → UserSelect[source]¶
Add a user select menu to this menu.
- Parameters:
on_select – The asynchronous function to call when the select menu is submitted.
custom_id – The custom ID for the select menu. Only specify this when you are creating a persistent menu. If unspecified, one will be generated for you.
placeholder – The placeholder string for the select menu.
min_values – The minimum number of values that can be selected.
max_values – The maximum number of values that can be selected.
disabled – Whether the select menu is disabled.
- Returns:
The created select menu.
- async attach(client: client_.Client, *, wait: bool = True, timeout: float | None = 30) → MenuHandle[source]¶
Attach this menu to the given client, starting it. You may optionally wait for the menu to finish and/or provide a timeout, after which an
asyncio.TimeoutError
will be raised.- Parameters:
client – The client to attach the menu to.
wait – Whether to wait for the menu to finish. Defaults to
True
.timeout – The amount of time in seconds before the menu will time out. Defaults to 30 seconds.
- Returns:
An awaitable proxying the menu’s interaction consumer. You can await this directly in order to wait for the menu to finish if you passed
wait=False
.- Raises:
TimeoutError – If the timeout is exceeded, and
wait=True
. If you wait on the returned awaitable instead, the error will be raised from that statement.
- clear_current_row() → t_ex.Self¶
Remove all components from the current row.
- clear_rows() → t_ex.Self¶
Remove all components from this container.
- count(value) → integer -- return number of occurrences of value¶
- disable_all_components() → t_ex.Self[source]¶
Utility function to set all components within this menu as disabled.
- Returns:
The menu instance, for method chaining.
- enable_all_components() → t_ex.Self[source]¶
Utility function to set all components within this menu as enabled.
- Returns:
The menu instance, for method chaining
- index(value[, start[, stop]]) → integer -- return first index of value.¶
Raises ValueError if the value is not present.
Supporting start and stop arguments is optional, but recommended.
- next_row() → t_ex.Self¶
Move the current row pointer to the next row.
- async predicate(ctx: MenuContext) → bool[source]¶
The interaction predicate for this menu. This will be called before the appropriate component callback function is called, and should return a boolean indicating whether to continue and invoke the callback.
You could use this to check that the correct user has pressed a button, has the correct permissions, or anything else you’d need to check before running component logic.
By default, the implementation of this function always returns
True
and performs no logic.- Parameters:
ctx – The context for this component invocation.
- Returns:
Boolean indicating whether the component callback function should be called.
- previous_row() → t_ex.Self¶
Move the current row pointer back to the previous row.
- class MenuContext(client: client_.Client, menu: Menu, interaction: ComponentInteraction, component: BaseComponent[special_endpoints.MessageActionRowBuilder], _timeout: async_timeout.Timeout)[source]¶
Class representing the context for an invocation of a component that belongs to a menu.
- async defer(*, ephemeral: bool = False, edit: bool = False) → None¶
Defer the creation of a response for the interaction that this context represents.
- Parameters:
ephemeral – Whether to defer ephemerally (message only visible to the user that triggered the command).
edit – Whether the eventual response should cause an edit instead of creating a new message.
- Returns:
- async delete_response(response_id: Snowflake | int) → None¶
Delete the response with the given identifier.
- Parameters:
response_id – The identifier of the response to delete - as returned by
respond()
.- Returns:
- async edit_response(response_id: hikari.Snowflakeish, content: hikari.UndefinedNoneOr[t.Any] = UNDEFINED, *, attachment: hikari.UndefinedNoneOr[hikari.Resourceish | Attachment] = UNDEFINED, attachments: hikari.UndefinedNoneOr[Sequence[hikari.Resourceish | Attachment]] = UNDEFINED, component: hikari.UndefinedNoneOr[special_endpoints.ComponentBuilder] = UNDEFINED, components: hikari.UndefinedNoneOr[Sequence[special_endpoints.ComponentBuilder]] = UNDEFINED, embed: hikari.UndefinedNoneOr[Embed] = UNDEFINED, embeds: hikari.UndefinedNoneOr[Sequence[Embed]] = UNDEFINED, mentions_everyone: hikari.UndefinedOr[bool] = UNDEFINED, user_mentions: hikari.UndefinedOr[hikari.SnowflakeishSequence[PartialUser] | bool] = UNDEFINED, role_mentions: hikari.UndefinedOr[hikari.SnowflakeishSequence[PartialRole] | bool] = UNDEFINED) → Message¶
Edit the response with the given identifier.
- Parameters:
response_id – The identifier of the response to delete - as returned by
respond()
.content – The message contents.
attachment – The message attachment.
attachments – The message attachments.
component – The builder object of the component to include in this message.
components – The sequence of the component builder objects to include in this message.
embed – The message embed.
embeds – The message embeds.
mentions_everyone – Whether the message should parse @everyone/@here mentions.
user_mentions – The user mentions to include in the message.
role_mentions – The role mentions to include in the message.
- Returns:
The updated message object for the response with the given identifier.
- Return type:
Note
This documentation does not contain a full description of the parameters as they would just be copy-pasted from the hikari documentation. See
edit_initial_response()
for a more detailed description.
- extend_timeout(length: float) → None[source]¶
Extend the menu’s timeout by the given length.
- Parameters:
length – The number of seconds to extend the timeout for.
- Returns:
- async fetch_response(response_id: Snowflake | int) → Message¶
Fetch the message object for the response with the given identifier.
- Parameters:
response_id – The identifier of the response to fetch - as returned by
respond()
.- Returns:
The message for the response with the given identifier.
- Return type:
- async respond(content: hikari.UndefinedOr[t.Any] = UNDEFINED, *, ephemeral: bool = False, edit: bool = False, rebuild_menu: bool = False, flags: int | MessageFlag | UndefinedType = UNDEFINED, tts: hikari.UndefinedOr[bool] = UNDEFINED, attachment: hikari.UndefinedOr[hikari.Resourceish] = UNDEFINED, attachments: hikari.UndefinedOr[Sequence[hikari.Resourceish]] = UNDEFINED, component: hikari.UndefinedOr[special_endpoints.ComponentBuilder] = UNDEFINED, components: hikari.UndefinedOr[Sequence[special_endpoints.ComponentBuilder]] = UNDEFINED, embed: hikari.UndefinedOr[Embed] = UNDEFINED, embeds: hikari.UndefinedOr[Sequence[Embed]] = UNDEFINED, mentions_everyone: hikari.UndefinedOr[bool] = UNDEFINED, user_mentions: hikari.UndefinedOr[hikari.SnowflakeishSequence[PartialUser] | bool] = UNDEFINED, role_mentions: hikari.UndefinedOr[hikari.SnowflakeishSequence[PartialRole] | bool] = UNDEFINED) → hikari.Snowflakeish[source]¶
Create a response to the interaction that this context represents.
- Parameters:
content – The message contents.
ephemeral – Whether the message should be ephemeral (only visible to the user that triggered the command). This is just a convenience argument - passing flags=hikari.MessageFlag.EPHEMERAL will function the same way.
edit – Whether the response should cause an edit instead of creating a new message.
rebuild_menu – Whether the menu this context is for should be rebuilt and sent with the response. This is just a convenience argument - passing components=menu will function the same way. If you also pass a value to
components
, that value will be used instead.attachment – The message attachment.
attachments – The message attachments.
component – The builder object of the component to include in this message.
components – The sequence of the component builder objects to include in this message.
embed – The message embed.
embeds – The message embeds.
flags – The message flags this response should have.
tts – Whether the message will be read out by a screen reader using Discord’s TTS (text-to-speech) system.
mentions_everyone – Whether the message should parse @everyone/@here mentions.
user_mentions – The user mentions to include in the message.
role_mentions – The role mentions to include in the message.
- Returns:
- An identifier for the response. This can then be used to edit,
delete, or fetch the response message using the appropriate methods.
- Return type:
Note
This documentation does not contain a full description of the parameters as they would just be copy-pasted from the hikari documentation. See
create_initial_response
for a more detailed description.Note
If this is not creating an initial response and
edit
is :obj:True`, then this will always edit the initial response, not the most recently created response.
- async respond_with_modal(title: str, custom_id: str, component: ComponentBuilder | UndefinedType = UNDEFINED, components: Sequence[ComponentBuilder] | UndefinedType = UNDEFINED) → None[source]¶
Create a modal response to the interaction that this context represents.
- Parameters:
title – The title that will show up in the modal.
custom_id – Developer set custom ID used for identifying interactions with this modal.
component – A component builder to send in this modal.
components – A sequence of component builders to send in this modal.
- Returns:
- Raises:
RuntimeError – If an initial response has already been sent.
- selected_values_for(select: Select[T]) → Sequence[T][source]¶
Get the values the user selected for the given select menu.
- Parameters:
select – The select menu component to get the selected values for.
- Returns:
The selected values.
- set_timeout(timeout: float) → None[source]¶
Override the menu’s timeout, resetting it to the given value.
- Parameters:
timeout – The number of seconds to set the timeout for.
- Returns:
- client: client_.Client¶
The client that is handling interactions for this context.
- component: BaseComponent[special_endpoints.MessageActionRowBuilder]¶
The component that triggered the interaction for this context.
- property guild_id: Snowflake | None¶
The ID of the guild that the interaction was created in.
None
if the interaction occurred in DM.
- property interaction: ComponentInteraction¶
The interaction that this context is for.
- property member: InteractionMember | None¶
The member that created the interaction, if it was created in a guild.
- class MenuHandle(task: Task[None])[source]¶
Class encapsulating a single instance of an interaction listener for a component menu. Can be awaited in order to block until the menu completes.
- class RoleSelect(custom_id: str, placeholder: hikari.UndefinedOr[str], min_values: int, max_values: int, disabled: bool, callback: ComponentCallback)[source]¶
Class representing a select menu with role options.
- add_to_row(row: MessageActionRowBuilder) → MessageActionRowBuilder[source]¶
Add this component to the given action row builder, and return the updated builder.
- Parameters:
row – The row to add the component to.
- Returns:
The updated builder.
- callback: ComponentCallback¶
The callback method to call when the select menu is submitted.
- class Select(custom_id: str, placeholder: hikari.UndefinedOr[str], min_values: int, max_values: int, disabled: bool, callback: ComponentCallback)[source]¶
Dataclass representing a generic select menu.
- abstract add_to_row(row: RowT) → RowT¶
Add this component to the given action row builder, and return the updated builder.
- Parameters:
row – The row to add the component to.
- Returns:
The updated builder.
- callback: ComponentCallback¶
The callback method to call when the select menu is submitted.
- class TextSelect(custom_id: str, placeholder: hikari.UndefinedOr[str], min_values: int, max_values: int, disabled: bool, callback: ComponentCallback, options: ValidSelectOptions)[source]¶
Class representing a select menu with text options.
- add_to_row(row: MessageActionRowBuilder) → MessageActionRowBuilder[source]¶
Add this component to the given action row builder, and return the updated builder.
- Parameters:
row – The row to add the component to.
- Returns:
The updated builder.
- callback: ComponentCallback¶
The callback method to call when the select menu is submitted.
- options: ValidSelectOptions¶
The options for the select menu.
- class TextSelectOption(label: str, value: str, description: str | UndefinedType = UNDEFINED, emoji: Snowflake | int | str | Emoji | UndefinedType = UNDEFINED, default: bool = False)[source]¶
Class representing an option for a text select menu.
- description: str | UndefinedType¶
The description of the option.
- class UserSelect(custom_id: str, placeholder: hikari.UndefinedOr[str], min_values: int, max_values: int, disabled: bool, callback: ComponentCallback)[source]¶
Class representing a select menu with user options.
- add_to_row(row: MessageActionRowBuilder) → MessageActionRowBuilder[source]¶
Add this component to the given action row builder, and return the updated builder.
- Parameters:
row – The row to add the component to.
- Returns:
The updated builder.
- callback: ComponentCallback¶
The callback method to call when the select menu is submitted.