View
The main class for creating interactive message components.Constructor
Initial items attached to this view.
Timeout in seconds from last interaction before no longer accepting input. If
None, there is no timeout.Whether to disable the view when the timeout is reached.
Whether this view should be stored for callback listening. Setting to
False ignores item callbacks and prevents value refreshing.Attributes
Timeout from last interaction with the UI before no longer accepting input.
The list of children attached to this view.
Whether to disable the view when the timeout is reached.
The message that this view is attached to.
None if the view has not been sent.The parent interaction which this view was sent from.
None if not sent using InteractionResponse.send_message.Methods
add_item
add_item
Adds an item to the view.Parameters:
item(ViewItem): The item to add to the view.
TypeError: An ViewItem was not passed.ValueError: Maximum number of children exceeded (25) or row is full.
Selfremove_item
remove_item
Removes an item from the view.Parameters:
item(ViewItem | int | str): The item, itemid, or itemcustom_idto remove.
Selfclear_items
clear_items
Removes all items from the view.Returns:
Selfinteraction_check
interaction_check
A callback that checks whether the view should process item callbacks for an interaction.Parameters:
interaction(Interaction): The interaction that occurred.
bool - Whether the view children’s callbacks should be called.on_timeout
on_timeout
A callback called when a view’s timeout elapses without being explicitly stopped.
on_check_failure
on_check_failure
A callback called when
interaction_check returns False.Parameters:interaction(Interaction): The interaction that occurred.
on_error
on_error
A callback called when an item’s callback or
interaction_check fails with an error.Parameters:error(Exception): The exception that was raised.item(ViewItem): The item that failed the dispatch.interaction(Interaction): The interaction that led to the failure.
disable_all_items
disable_all_items
Disables all buttons and select menus in the view.Parameters:
exclusions(List[ViewItem] | None): Items to not disable from the view.
Selfenable_all_items
enable_all_items
Enables all buttons and select menus in the view.Parameters:
exclusions(List[ViewItem] | None): Items to not enable from the view.
Selfstop
stop
Stops listening to interaction events from this view. This operation cannot be undone.
wait
wait
Waits until the view has finished interacting.Returns:
bool - True if the view timed out, False if finished normally.is_finished
is_finished
Whether the view has finished interacting.Returns:
boolis_persistent
is_persistent
Whether the view is set up as persistent. A persistent view has all components with a set
custom_id and timeout set to None.Returns: boolfrom_message
from_message
Converts a message’s components into a View.Parameters:
message(Message): The message with components to convert.timeout(float | None): The timeout of the converted view. Defaults to 180.0.
ViewItem
Base class for all UI components.Attributes
The underlying component’s type.
The item’s ID. Set by the user or automatically by Discord.
Methods
is_dispatchable
is_dispatchable
Whether the item can dispatch interactions.Returns:
boolis_persistent
is_persistent
Whether the item is persistent (has a custom_id set).Returns:
boolViewItem
Base class for items used in Views.Attributes
The parent view associated with this item.
The width of the item in the UI layout (1-5).
Methods
callback
callback
The callback associated with this UI item. Override in subclasses.Parameters:
interaction(Interaction): The interaction that triggered this item.
