Copy Select options when creating View class

This commit is contained in:
Leonardo 2025-06-20 20:24:06 +02:00 committed by GitHub
parent 8d8d5e180a
commit 7f16a06479
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 0 deletions

View File

@ -442,6 +442,9 @@ class SelectOption:
return payload return payload
def copy(self) -> SelectOption:
return self.__class__.from_dict(self.to_dict())
class TextInput(Component): class TextInput(Component):
"""Represents a text input from the Discord Bot UI Kit. """Represents a text input from the Discord Bot UI Kit.

View File

@ -33,6 +33,7 @@ import sys
import time import time
import os import os
from .item import Item, ItemCallbackType from .item import Item, ItemCallbackType
from .select import Select
from .dynamic import DynamicItem from .dynamic import DynamicItem
from ..components import ( from ..components import (
Component, Component,
@ -179,6 +180,8 @@ class View:
item: Item = func.__discord_ui_model_type__(**func.__discord_ui_model_kwargs__) item: Item = func.__discord_ui_model_type__(**func.__discord_ui_model_kwargs__)
item.callback = _ViewCallback(func, self, item) # type: ignore item.callback = _ViewCallback(func, self, item) # type: ignore
item._view = self item._view = self
if isinstance(item, Select):
item.options = [option.copy() for option in item.options]
setattr(self, func.__name__, item) setattr(self, func.__name__, item)
children.append(item) children.append(item)
return children return children