Browse Source

chore: update container and things

pull/10166/head
DA-344 1 month ago
parent
commit
dbd8cd6cd3
  1. 9
      discord/ui/container.py
  2. 9
      discord/ui/section.py

9
discord/ui/container.py

@ -24,6 +24,7 @@ DEALINGS IN THE SOFTWARE.
from __future__ import annotations
import copy
import os
from typing import TYPE_CHECKING, Any, ClassVar, Coroutine, Dict, List, Literal, Optional, Tuple, Type, TypeVar, Union
from .item import Item, ItemCallbackType
@ -161,8 +162,14 @@ class Container(Item[V]):
if item.is_dispatchable():
self.__dispatchable.extend(item._children) # type: ignore
if getattr(raw, '__discord_ui_section__', False):
item = copy.copy(raw)
if item.accessory.is_dispatchable(): # type: ignore
item.accessory = copy.deepcopy(item.accessory) # type: ignore
if item.accessory._provided_custom_id is False: # type: ignore
item.accessory.custom_id = os.urandom(16).hex() # type: ignore
else:
item = raw
item = copy.copy(raw)
if getattr(item, '__discord_ui_section__', False) and item.accessory.is_dispatchable(): # type: ignore
self.__dispatchable.append(item.accessory) # type: ignore

9
discord/ui/section.py

@ -75,22 +75,21 @@ class Section(Item[V]):
def __init__(
self,
children: List[Union[Item[Any], str]] = MISSING,
children: List[Union[Item[V], str]] = MISSING,
*,
accessory: Item[Any],
accessory: Item[V],
row: Optional[int] = None,
id: Optional[int] = None,
) -> None:
super().__init__()
self._children: List[Item[Any]] = []
self._children: List[Item[V]] = []
if children is not MISSING:
if len(children) > 3:
raise ValueError('maximum number of children exceeded')
self._children.extend(
[c if isinstance(c, Item) else TextDisplay(c) for c in children],
)
self.accessory: Item[Any] = accessory
self.accessory: Item[V] = accessory
self.row = row
self.id = id

Loading…
Cancel
Save