Skip to content
This repository was archived by the owner on Mar 8, 2022. It is now read-only.

Commit fab9faa

Browse files
committed
2 parents 997e205 + 7b19dcf commit fab9faa

File tree

2 files changed

+10
-25
lines changed

2 files changed

+10
-25
lines changed

discord_ui/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@
4747

4848

4949
__title__ = "discord-ui"
50-
__version__ = "5.1.4"
50+
__version__ = "5.1.5"
5151
__author__ = "404kuso, RedstoneZockt"

discord_ui/components.py

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def __init__(self, options, custom_id=None, min_values=1, max_values=1, placehol
349349
```
350350
"""
351351
UseableComponent.__init__(self, ComponentType.Select)
352-
self._options = None
352+
self.options: List[SelectOption] = options or None
353353

354354
self.max_values: int = 0
355355
"""The maximum number of items that can be chosen; default 1, max 25"""
@@ -365,7 +365,6 @@ def __init__(self, options, custom_id=None, min_values=1, max_values=1, placehol
365365
Custom placeholder text if nothing is selected"""
366366
self.custom_id = custom_id or ''.join([choice(string.ascii_letters) for _ in range(100)])
367367
self.disabled = disabled
368-
self.options = options
369368

370369
if min_values is not None and max_values is None:
371370
if min_values < 0 or min_values > 25:
@@ -394,26 +393,12 @@ def __repr__(self) -> str:
394393

395394
@staticmethod
396395
def _from_data(data) -> SelectMenu:
397-
return SelectMenu(data["options"], data["custom_id"], data.get("min_values"), data.get("max_values"), data.get("placeholder"), disabled=data.get("disabled", False))
396+
return SelectMenu([
397+
SelectOption._from_data(d) for d in data["options"]
398+
], data["custom_id"], data.get("min_values"), data.get("max_values"), data.get("placeholder"), disabled=data.get("disabled", False)
399+
)
398400
# region props
399-
@property
400-
def options(self) -> List[SelectOption]:
401-
"""The options in the select menu to select from"""
402-
return [SelectOption._from_data(x) for x in self._options]
403-
@options.setter
404-
def options(self, value: List[SelectOption]):
405-
if isinstance(value, list):
406-
if len(value) > 25 or len(value) == 0:
407-
raise OutOfValidRange("length of options", 1, 25)
408-
if all(isinstance(x, SelectOption) for x in value):
409-
self._options = [x.to_dict() for x in value]
410-
elif all(isinstance(x, dict) for x in value):
411-
self._options = value
412-
else:
413-
raise WrongType("options", value, ["List[SelectOption]", "List[dict]"])
414-
else:
415-
raise WrongType("options", value, "list")
416-
401+
417402
@property
418403
def default_options(self) -> List[SelectOption]:
419404
"""The option selected by default"""
@@ -433,17 +418,17 @@ def set_default_option(self, position) -> SelectMenu:
433418
if isinstance(position, int):
434419
if position < 0 or position >= len(self.options):
435420
raise OutOfValidRange("default option position", 0, str(len(self.options) - 1))
436-
self._options[position].default = True
421+
self.options[position].default = True
437422
return self
438423
for pos in position:
439-
self._options[pos].default = True
424+
self.options[pos].default = True
440425
# endregion
441426

442427
def to_dict(self) -> dict:
443428
payload = {
444429
"type": self._component_type,
445430
"custom_id": self._custom_id,
446-
"options": self._options,
431+
"options": [x.to_dict() for x in self.options],
447432
"disabled": self.disabled,
448433
"min_values": self.min_values,
449434
"max_values": self.max_values

0 commit comments

Comments
 (0)