Item Handler API Reference#
ItemHandler
#
Bases: Sequence[BuilderT]
, abc.ABC
, t.Generic[BuilderT, RespBuilderT, ContextT, InteractionT, ItemT]
Abstract base class all item-handlers (e.g. views, modals) inherit from.
PARAMETER | DESCRIPTION |
---|---|
timeout |
The duration after which the item handler times out, in seconds
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HandlerFullError
|
Raised if the item handler has more than 25 components attached. |
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.
add_item
#
Adds a new item to the item handler.
PARAMETER | DESCRIPTION |
---|---|
item |
The item to be added.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
ItemHandler already has 25 components attached. |
TypeError
|
Parameter item is not an instance of Item. |
ItemAlreadyAttachedError
|
The item is already attached to this item handler. |
ItemAlreadyAttachedError
|
The item is already attached to another item handler. |
RETURNS | DESCRIPTION |
---|---|
ItemHandler
|
The item handler the item was added to. |
remove_item
#
Removes the specified item from the item handler.
PARAMETER | DESCRIPTION |
---|---|
item |
The item to be removed.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ItemHandler
|
The item handler the item was removed from. |
clear_items
#
Removes all items from this item handler.
RETURNS | DESCRIPTION |
---|---|
ItemHandler
|
The item handler items were cleared from. |
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.