View API Reference#
View
#
View(
*,
timeout: (
float | int | datetime.timedelta | None
) = 120.0,
autodefer: bool | AutodeferOptions = True
)
Bases: ItemHandler[hikari.impl.MessageActionRowBuilder, ResponseBuildersT, ViewContext, hikari.ComponentInteraction, ViewItem]
Represents a set of Discord UI components attached to a message.
PARAMETER | DESCRIPTION |
---|---|
timeout |
The duration after which the view times out, in seconds
TYPE:
|
autodefer |
If enabled, interactions will be automatically deferred if not responded to within 2 seconds You may also pass an instance of miru.AutodeferOptions to customize the autodefer behaviour.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
Raised if a view has more than 25 components attached. |
RuntimeError
|
Raised if miru.install() was never called before instantiation. |
timeout
property
#
timeout: float | None
The amount of time the item handler is allowed to idle for, in seconds. Must be None for persistent views.
last_context
property
#
The last context that was received by the item handler.
is_persistent
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.
message
property
#
The message this view is bound to. Will be None if the view is not bound.
get_item_by
#
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
#
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. |
build
#
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. |
on_timeout
async
#
Called when the item handler times out. Override for custom timeout logic.
wait
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:
|
from_message
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 |
add_item
#
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
#
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. |
clear_items
#
Removes all items from the view.
RETURNS | DESCRIPTION |
---|---|
View
|
The view the items were removed from. |
view_check
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. |
on_error
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:
|
wait_for_input
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:
|