From 492729cc42349c550f4f0d73de35510ca691bb8c Mon Sep 17 00:00:00 2001 From: unsmxrt <87228248+unsmxrt@users.noreply.github.com> Date: Sun, 7 May 2023 05:10:03 +0500 Subject: [PATCH] Fix ActionRow not implementing "to_dict()" (#496) * Fix ActionRow not implementing to_dict This would make modals impossible to submit, for example * Fix typing --------- Co-authored-by: dolfies --- discord/components.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/discord/components.py b/discord/components.py index 20df7484c..e36818485 100644 --- a/discord/components.py +++ b/discord/components.py @@ -35,6 +35,7 @@ if TYPE_CHECKING: from typing_extensions import Self from .types.components import ( + ActionRow as ActionRowPayload, Component as ComponentPayload, ButtonComponent as ButtonComponentPayload, SelectMenu as SelectMenuPayload, @@ -138,6 +139,13 @@ class ActionRow(Component): """:class:`ComponentType`: The type of component.""" return ComponentType.action_row + def to_dict(self) -> ActionRowPayload: + # NOTE: This will have to be changed for the inevitable selects in modals + return { + 'type': self.type.value, + 'components': [c.to_dict() for c in self.children], # type: ignore + } + class Button(Component): """Represents a button from the Discord Bot UI Kit. @@ -288,11 +296,11 @@ class SelectMenu(Component): """:class:`ComponentType`: The type of component.""" return ComponentType.select - def to_dict(self, options: Tuple[SelectOption]) -> dict: + def to_dict(self, options: Optional[Tuple[SelectOption]] = None) -> dict: return { 'component_type': self.type.value, 'custom_id': self.custom_id, - 'values': [option.value for option in options], + 'values': [option.value for option in options] if options else [], } async def choose(self, *options: SelectOption) -> Interaction: