Skip to content

Commit 3aabd40

Browse files
authored
update from_dict and docs
1 parent 19108ce commit 3aabd40

2 files changed

Lines changed: 28 additions & 8 deletions

File tree

discord/ui/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ class ItemInterface:
7979
timeout: Optional[:class:`float`]
8080
Timeout in seconds from last interaction with the UI before no longer accepting input. Defaults to 180.0.
8181
If ``None`` then there is no timeout.
82+
store: Optional[:class:`bool`]
83+
Whether this interface should be stored for callback listening. Setting it to ``False`` will ignore callbacks and prevent item values from being refreshed. Defaults to ``True``.
8284
8385
Attributes
8486
----------
@@ -87,8 +89,6 @@ class ItemInterface:
8789
If ``None`` then there is no timeout.
8890
children: List[:class:`Item`]
8991
The list of children attached to this structure.
90-
store: Optional[:class:`bool`]
91-
Whether this interface should be stored for callback listening. Setting it to ``False`` will ignore callbacks and prevent item values from being refreshed. Defaults to ``True``.
9292
"""
9393

9494
def __init__(

discord/ui/view.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,8 @@ class View(BaseView):
585585
timeout: Optional[:class:`float`]
586586
Timeout in seconds from last interaction with the UI before no longer accepting input. Defaults to 180.0.
587587
If ``None`` then there is no timeout.
588+
disable_on_timeout: :class:`bool`
589+
Whether to disable the view when the timeout is reached. Defaults to ``False``.
588590
store: Optional[:class:`bool`]
589591
Whether this view should be stored for callback listening. Setting it to ``False`` will ignore item callbacks and prevent their values from being refreshed. Defaults to ``True``.
590592
@@ -595,8 +597,6 @@ class View(BaseView):
595597
If ``None`` then there is no timeout.
596598
children: List[:class:`ViewItem`]
597599
The list of children attached to this view.
598-
disable_on_timeout: :class:`bool`
599-
Whether to disable the view when the timeout is reached. Defaults to ``False``.
600600
message: Optional[:class:`.Message`]
601601
The message that this view is attached to.
602602
If ``None`` then the view has not been sent with a message.
@@ -688,6 +688,10 @@ def from_message(
688688
The message with components to convert into a view.
689689
timeout: Optional[:class:`float`]
690690
The timeout of the converted view.
691+
disable_on_timeout: :class:`bool`
692+
Whether to disable the view when the timeout is reached. Defaults to ``False``.
693+
store: Optional[:class:`bool`]
694+
Whether this view should be stored for callback listening. Setting it to ``False`` will ignore item callbacks and prevent their values from being refreshed. Defaults to ``True``.
691695
692696
Returns
693697
-------
@@ -707,6 +711,8 @@ def from_dict(
707711
/,
708712
*,
709713
timeout: float | None = 180.0,
714+
disable_on_timeout: bool = False,
715+
store: bool = True,
710716
) -> View:
711717
"""Converts a list of component dicts into a :class:`View`.
712718
@@ -716,14 +722,18 @@ def from_dict(
716722
The list of components to convert into a view.
717723
timeout: Optional[:class:`float`]
718724
The timeout of the converted view.
725+
disable_on_timeout: :class:`bool`
726+
Whether to disable the view when the timeout is reached. Defaults to ``False``.
727+
store: Optional[:class:`bool`]
728+
Whether this view should be stored for callback listening. Setting it to ``False`` will ignore item callbacks and prevent their values from being refreshed. Defaults to ``True``.
719729
720730
Returns
721731
-------
722732
:class:`View`
723733
The converted view. This always returns a :class:`View` and not
724734
one of its subclasses.
725735
"""
726-
view = View(timeout=timeout)
736+
view = View(timeout=timeout, disable_on_timeout=disable_on_timeout, store=store)
727737
components = [_component_factory(d) for d in data]
728738
for component in _walk_all_components(components):
729739
view.add_item(_component_to_item(component))
@@ -830,6 +840,8 @@ class DesignerView(BaseView):
830840
timeout: Optional[:class:`float`]
831841
Timeout in seconds from last interaction with the UI before no longer accepting input. Defaults to 180.0.
832842
If ``None`` then there is no timeout.
843+
disable_on_timeout: :class:`bool`
844+
Whether to disable the view's items when the timeout is reached. Defaults to ``False``.
833845
store: Optional[:class:`bool`]
834846
Whether this view should be stored for callback listening. Setting it to ``False`` will ignore item callbacks and prevent their values from being refreshed. Defaults to ``True``.
835847
@@ -840,8 +852,6 @@ class DesignerView(BaseView):
840852
If ``None`` then there is no timeout.
841853
children: List[:class:`ViewItem`]
842854
The list of items attached to this view.
843-
disable_on_timeout: :class:`bool`
844-
Whether to disable the view's items when the timeout is reached. Defaults to ``False``.
845855
message: Optional[:class:`.Message`]
846856
The message that this view is attached to.
847857
If ``None`` then the view has not been sent with a message.
@@ -902,6 +912,10 @@ def from_message(
902912
The message with components to convert into a view.
903913
timeout: Optional[:class:`float`]
904914
The timeout of the converted view.
915+
disable_on_timeout: :class:`bool`
916+
Whether to disable the view when the timeout is reached. Defaults to ``False``.
917+
store: Optional[:class:`bool`]
918+
Whether this view should be stored for callback listening. Setting it to ``False`` will ignore item callbacks and prevent their values from being refreshed. Defaults to ``True``.
905919
906920
Returns
907921
-------
@@ -923,6 +937,8 @@ def from_dict(
923937
/,
924938
*,
925939
timeout: float | None = 180.0,
940+
disable_on_timeout: bool = False,
941+
store: bool = True,
926942
) -> DesignerView:
927943
"""Converts a list of component dicts into a :class:`DesignerView`.
928944
@@ -932,14 +948,18 @@ def from_dict(
932948
The list of components to convert into a view.
933949
timeout: Optional[:class:`float`]
934950
The timeout of the converted view.
951+
disable_on_timeout: :class:`bool`
952+
Whether to disable the view when the timeout is reached. Defaults to ``False``.
953+
store: Optional[:class:`bool`]
954+
Whether this view should be stored for callback listening. Setting it to ``False`` will ignore item callbacks and prevent their values from being refreshed. Defaults to ``True``.
935955
936956
Returns
937957
-------
938958
:class:`DesignerView`
939959
The converted view. This always returns a :class:`DesignerView` and not
940960
one of its subclasses.
941961
"""
942-
view = DesignerView(timeout=timeout)
962+
view = DesignerView(timeout=timeout, disable_on_timeout=disable_on_timeout, store=store)
943963
components = [_component_factory(d) for d in data]
944964
for component in components:
945965
view.add_item(_component_to_item(component))

0 commit comments

Comments
 (0)