Skip to content

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: str | None DEFAULT: None

custom_id

The custom identifier of the modal, identifies the modal through interactions.

TYPE: str DEFAULT: None

timeout

The duration after which the modal times out, in seconds

TYPE: Optional[Union[float, int, datetime.timedelta]] DEFAULT: 300.0

RAISES DESCRIPTION
HandlerFullError

Raised if the modal has more than 25 components attached.

children property #

children: t.Sequence[ItemT]

A list of all items attached to the item handler.

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.

client property #

client: Client

The client that started this handler.

last_context property #

last_context: ContextT | None

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.

values property #

values: t.Mapping[ModalItem, str] | None

The input values received by this modal.

remove_item #

remove_item(item: ItemT) -> te.Self

Removes the specified item from the item handler.

PARAMETER DESCRIPTION
item

The item to be removed.

TYPE: Item[Any]

RETURNS DESCRIPTION
ItemHandler

The item handler the item was removed from.

clear_items #

clear_items() -> te.Self

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.

TYPE: Callable[[Item[Any]], bool]

default

The default value to return if the item doesn't exist.

TYPE: T DEFAULT: hikari.UNDEFINED

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: str

default

The default value to return if the item doesn't exist.

TYPE: T DEFAULT: hikari.UNDEFINED

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 #

build() -> t.Sequence[BuilderT]

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 #

on_timeout() -> None

Called when the item handler times out. Override for custom timeout logic.

stop #

stop() -> None

Stop listening for interactions.

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: Optional[float] DEFAULT: None

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: ModalItem

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: Context

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: Exception

context

The context associated with this exception, if any.

TYPE: Optional[Context] DEFAULT: None

callback async #

callback(context: ModalContext) -> None

Called when the modal is submitted.

PARAMETER DESCRIPTION
context

The context that belongs to this interaction callback.

TYPE: ModalContext

build_response #

build_response(client: Client) -> ModalBuilder

Build the modal response for this modal.