Menu API Reference#
Menu(
    *,
    timeout: (
        float | int | datetime.timedelta | None
    ) = 300.0,
    autodefer: bool | miru.AutodeferOptions = True
)
              Bases: miru.View
A menu that can be used to display multiple nested screens of components.
| PARAMETER | DESCRIPTION | 
|---|---|
| timeout | The duration after which the menu times out, in seconds 
                  
                    TYPE:
                       | 
| autodefer | If enabled, interactions will be automatically deferred if not responded to within 2 seconds 
                  
                    TYPE:
                       | 
property
  
#
timeout: float | None
The amount of time the item handler is allowed to idle for, in seconds. Must be None for persistent views.
property
  
#
    The last context that was received by the item handler.
property
  
#
    The message this view is bound to. Will be None if the view is not bound.
property
  
#
is_persistent: bool
Determines if this view is persistent or not. A view is persistent only if it has no timeout and all of it's items have explicitly set custom_ids.
add_item(item: ViewItem) -> te.Self
Adds a new item to the view.
| PARAMETER | DESCRIPTION | 
|---|---|
| item | The item to be added. 
                  
                    TYPE:
                       | 
| RAISES | DESCRIPTION | 
|---|---|
| ValueError | A view already has 25 components attached. | 
| TypeError | Parameter item is not an instance of ViewItem. | 
| RuntimeError | The item is already attached to this view. | 
| RuntimeError | The item is already attached to another view. | 
| RETURNS | DESCRIPTION | 
|---|---|
| View | The view the item was added to. | 
remove_item(item: ViewItem) -> te.Self
Removes an item from the view.
| PARAMETER | DESCRIPTION | 
|---|---|
| item | The item to be removed. 
                  
                    TYPE:
                       | 
| RAISES | DESCRIPTION | 
|---|---|
| ValueError | The item is not attached to this view. | 
| RETURNS | DESCRIPTION | 
|---|---|
| View | The view the item was removed from. | 
    Removes all items from the view.
| RETURNS | DESCRIPTION | 
|---|---|
| View | The view the items were removed from. | 
get_item_by(
    predicate: t.Callable[[ItemT], bool],
    *,
    default: T | hikari.UndefinedType = hikari.UNDEFINED
) -> ItemT | T
Get the first item that matches the given predicate.
| PARAMETER | DESCRIPTION | 
|---|---|
| predicate | A predicate to match the item. | 
| default | The default value to return if the item doesn't exist. | 
| RETURNS | DESCRIPTION | 
|---|---|
| ItemT | T | The item that matched the predicate or default. | 
| RAISES | DESCRIPTION | 
|---|---|
| KeyError | No item that matches predicate was found and no default was provided. | 
get_item_by_id(
    custom_id: str,
    default: T | hikari.UndefinedType = hikari.UNDEFINED,
) -> ItemT | T
Get the first item that matches the given custom ID.
| PARAMETER | DESCRIPTION | 
|---|---|
| custom_id | The custom_id of the component. 
                  
                    TYPE:
                       | 
| default | The default value to return if the item doesn't exist. | 
| RETURNS | DESCRIPTION | 
|---|---|
| ItemT | T | The item that matched the custom ID or the default. | 
| RAISES | DESCRIPTION | 
|---|---|
| KeyError | No item that matches the custom ID was found and no default was provided. | 
    Creates the action rows the item handler represents.
| RETURNS | DESCRIPTION | 
|---|---|
| List[hikari.impl.MessageActionRowBuilder] | A list of action rows containing all items attached to this item handler, converted to hikari component objects. If the item handler has no items attached, this returns an empty list. | 
async
  
#
wait(timeout: float | None = None) -> None
Wait until the item handler has stopped receiving interactions.
| PARAMETER | DESCRIPTION | 
|---|---|
| timeout | The amount of time to wait, in seconds 
                  
                    TYPE:
                       | 
classmethod
  
#
from_message(
    message: hikari.Message,
    *,
    timeout: (
        float | int | datetime.timedelta | None
    ) = 120.0,
    autodefer: bool = True
) -> te.Self
Create a new view from the components included in the passed message. Returns an empty view if the message has no components attached.
| PARAMETER | DESCRIPTION | 
|---|---|
| message | The message to read components from | 
| timeout | The timeout of the created view 
                  
                    TYPE:
                       | 
| autodefer | If enabled, interactions will be automatically deferred if not responded to within 2 seconds 
                  
                    TYPE:
                       | 
| RETURNS | DESCRIPTION | 
|---|---|
| View | The view that represents the components attached to this message. | 
| !!! warning | This function constructs a completely new view based on the information available in the message object.
Any custom behaviour (such as callbacks) will not be re-created,
if you want to access an already running view that is bound to a message, use  | 
async
  
#
view_check(context: ViewContext) -> bool
Called before any callback in the view is called. Must evaluate to a truthy value to pass. Override for custom check logic.
| PARAMETER | DESCRIPTION | 
|---|---|
| context | The context for this check. 
                  
                    TYPE:
                       | 
| RETURNS | DESCRIPTION | 
|---|---|
| bool | A boolean indicating if the check passed or not. | 
async
  
#
on_error(
    error: Exception,
    item: InteractiveViewItem | None = None,
    context: ViewContext | None = None,
) -> None
Called when an error occurs in a callback function or the built-in timeout function. Override for custom error-handling logic.
| PARAMETER | DESCRIPTION | 
|---|---|
| error | The exception encountered. 
                  
                    TYPE:
                       | 
| item | The item this exception originates from, if any. 
                  
                    TYPE:
                       | 
| context | The context associated with this exception, if any. 
                  
                    TYPE:
                       | 
async
  
#
wait_for_input(timeout: float | None = None) -> None
Wait for any input to be received. This will also unblock if the view was stopped, thus it is recommended to check for the presence of a value after this function returns.
| PARAMETER | DESCRIPTION | 
|---|---|
| timeout | The amount of time to wait for input, in seconds 
                  
                    TYPE:
                       | 
async
  
#
    Called when the item handler times out. Override for custom timeout logic.
async
  
#
update_message(
    new_content: ScreenContent | None = None,
) -> None
Update the message with the current state of the menu.
| PARAMETER | DESCRIPTION | 
|---|---|
| new_content | The new content to use, if left as None, only the components will be updated 
                  
                    TYPE:
                       | 
async
  
#
push(screen: Screen) -> None
Push a screen onto the menu stack and display it.
| PARAMETER | DESCRIPTION | 
|---|---|
| screen | The screen to push onto the stack and display. 
                  
                    TYPE:
                       | 
async
  
#
pop(*, count: int = 1) -> None
Pop 'count' screen off the menu stack and display the screen on top of the stack. This can be used to go back to the previous screen(s).
| PARAMETER | DESCRIPTION | 
|---|---|
| count | The number of screens to pop off the stack. Defaults to 1 
                  
                    TYPE:
                       | 
| RAISES | DESCRIPTION | 
|---|---|
| ValueError | Cannot pop less than 1 screen. | 
| ValueError | Cannot pop the last screen. | 
async
  
#
    Pop all screens off the menu stack until the root screen is reached.
async
  
#
build_response_async(
    client: miru.Client,
    starting_screen: Screen,
    *,
    ephemeral: bool = False
) -> miru.MessageBuilder
Create a REST response builder out of this Menu.
Tip
If it takes too long to build the starting screen, you may want to defer the interaction before calling this method.
| PARAMETER | DESCRIPTION | 
|---|---|
| client | The client instance to use to build the response 
                  
                    TYPE:
                       | 
| starting_screen | The screen to start the menu with. 
                  
                    TYPE:
                       | 
| ephemeral | Determines if the navigator will be sent ephemerally or not. 
                  
                    TYPE:
                       |