Skip to content

Commit 9fec46c

Browse files
committed
fix: add a check to all SelectOptions conversions
1 parent d8bfc5a commit 9fec46c

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

interactions/api/models/channel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ async def send(
297297
):
298298
if isinstance(component, SelectMenu):
299299
component._json["options"] = [
300-
option._json for option in component.options
300+
option._json if not isinstance(option, dict) else option
301+
for option in component.options
301302
]
302303
_components.append(
303304
{

interactions/api/models/member.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ async def send(
314314
):
315315
if isinstance(component, SelectMenu):
316316
component._json["options"] = [
317-
option._json for option in component.options
317+
option._json if not isinstance(option, dict) else option
318+
for option in component.options
318319
]
319320
_components.append(
320321
{

interactions/api/models/message.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,8 @@ async def reply(
620620
):
621621
if isinstance(component, SelectMenu):
622622
component._json["options"] = [
623-
option._json for option in component.options
623+
option._json if not isinstance(option, dict) else option
624+
for option in component.options
624625
]
625626
_components.append(
626627
{

interactions/api/models/message.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ class Message(DictSerializerMixin):
114114
] = MISSING,
115115
) -> "Message": ...
116116

117-
async def reply(self,
117+
async def reply(
118+
self,
118119
content: Optional[str] = MISSING,
119120
*,
120121
tts: Optional[bool] = MISSING,

interactions/context.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ async def send(
232232
_components: List[dict] = [{"type": 1, "components": []}]
233233

234234
# TODO: Break this obfuscation pattern down to a "builder" method.
235-
if components is not MISSING:
235+
if components is not MISSING and components:
236+
# components could be not missing but an empty list
236237
if isinstance(components, list) and all(
237238
isinstance(action_row, ActionRow) for action_row in components
238239
):
@@ -282,7 +283,8 @@ async def send(
282283
):
283284
if isinstance(component, SelectMenu):
284285
component._json["options"] = [
285-
option._json for option in component.options
286+
option._json if not isinstance(option, dict) else option
287+
for option in component.options
286288
]
287289
_components.append(
288290
{
@@ -505,7 +507,8 @@ async def edit(
505507
):
506508
if isinstance(components[0], SelectMenu):
507509
components[0]._json["options"] = [
508-
option._json for option in components[0].options
510+
option._json if not isinstance(option, dict) else option
511+
for option in components[0].options
509512
]
510513
_components = [
511514
{
@@ -533,7 +536,8 @@ async def edit(
533536
):
534537
if isinstance(component, SelectMenu):
535538
component._json["options"] = [
536-
option._json for option in component.options
539+
option._json if not isinstance(option, dict) else option
540+
for option in component.options
537541
]
538542
_components.append(
539543
{
@@ -562,7 +566,17 @@ async def edit(
562566
)
563567
for component in components.components
564568
]
565-
elif isinstance(components, (Button, SelectMenu)):
569+
elif isinstance(components, Button):
570+
_components[0]["components"] = (
571+
[components._json]
572+
if components._json.get("custom_id") or components._json.get("url")
573+
else []
574+
)
575+
elif isinstance(components, SelectMenu):
576+
components._json["options"] = [
577+
options._json if not isinstance(options, dict) else options
578+
for options in components._json["options"]
579+
]
566580
_components[0]["components"] = (
567581
[components._json]
568582
if components._json.get("custom_id") or components._json.get("url")

0 commit comments

Comments
 (0)