From dbd8cd6cd33f3e17ef961d275a14b75609e8a6a0 Mon Sep 17 00:00:00 2001 From: DA-344 <108473820+DA-344@users.noreply.github.com> Date: Wed, 23 Apr 2025 21:33:37 +0200 Subject: [PATCH] chore: update container and things --- discord/ui/container.py | 9 ++++++++- discord/ui/section.py | 9 ++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/discord/ui/container.py b/discord/ui/container.py index 4c8b254e1..c9222262b 100644 --- a/discord/ui/container.py +++ b/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 diff --git a/discord/ui/section.py b/discord/ui/section.py index 11de2ec18..5d922a51a 100644 --- a/discord/ui/section.py +++ b/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