Skip to content

Copy select options when creating View class #10143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions discord/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from .partial_emoji import PartialEmoji, _EmojiTag

if TYPE_CHECKING:
from typing_extensions import Self

Check warning on line 33 in discord/components.py

View workflow job for this annotation

GitHub Actions / check 3.x

Import "typing_extensions" could not be resolved from source (reportMissingModuleSource)

from .types.components import (
Component as ComponentPayload,
Expand Down Expand Up @@ -442,6 +442,9 @@

return payload

def copy(self) -> SelectOption:
return self.__class__.from_dict(self.to_dict())


class TextInput(Component):
"""Represents a text input from the Discord Bot UI Kit.
Expand Down
3 changes: 3 additions & 0 deletions discord/ui/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import time
import os
from .item import Item, ItemCallbackType
from .select import Select
from .dynamic import DynamicItem
from ..components import (
Component,
Expand Down Expand Up @@ -179,6 +180,8 @@ def _init_children(self) -> List[Item[Self]]:
item: Item = func.__discord_ui_model_type__(**func.__discord_ui_model_kwargs__)
item.callback = _ViewCallback(func, self, item) # type: ignore
item._view = self
if isinstance(item, Select):
item.options = [option.copy() for option in item.options]
setattr(self, func.__name__, item)
children.append(item)
return children
Expand Down
Loading