Modal#
Modal
#
Modal(
title: str | None = None,
*,
custom_id: str | None = None,
timeout: float | int | datetime.timedelta | None = 300.0
)
Bases: ItemHandler[hikari.impl.ModalActionRowBuilder, ModalResponseBuildersT, ModalContext, hikari.ModalInteraction, ModalItem]
Represents a Discord Modal.
PARAMETER | DESCRIPTION |
---|---|
title |
The title of the modal, appears on the top of the modal dialog box. If not provided, it must be provided as a class variable.
TYPE:
|
custom_id |
The custom identifier of the modal, identifies the modal through interactions.
TYPE:
|
timeout |
The duration after which the modal times out, in seconds
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HandlerFullError
|
Raised if the modal 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.
title
property
writable
#
title: str
The title of this modal. Will be displayed on the top of the modal prompt.
custom_id
property
writable
#
custom_id: str
The custom identifier of this modal. Interactions belonging to it are tracked by this ID.
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.
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:
|
add_item
#
add_item(item: ModalItem) -> te.Self
Adds a new item to the modal.
PARAMETER | DESCRIPTION |
---|---|
item |
An instance of ModalItem to be added.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
TypeError
|
item is not of type ModalItem. |
ValueError
|
The modal already has 25 components attached. |
TypeError
|
Parameter item is not an instance of ModalItem. |
RuntimeError
|
The item is already attached to this view. |
RuntimeError
|
The item is already attached to another view. |
RETURNS | DESCRIPTION |
---|---|
ItemHandler
|
The item handler the item was added to. |
modal_check
async
#
modal_check(context: ModalContext) -> bool
Called before any callback in the modal 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, context: ModalContext | None = None
) -> None
Called when an error occurs in a callback function. Override for custom error-handling logic.
PARAMETER | DESCRIPTION |
---|---|
error |
The exception encountered.
TYPE:
|
context |
The context associated with this exception, if any.
TYPE:
|
callback
async
#
callback(context: ModalContext) -> None
Called when the modal is submitted.
PARAMETER | DESCRIPTION |
---|---|
context |
The context that belongs to this interaction callback.
TYPE:
|
build_response
#
build_response(client: Client) -> ModalBuilder
Build the modal response for this modal.