Browse Source

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 <[email protected]>
pull/10109/head
unsmxrt 2 years ago
committed by GitHub
parent
commit
492729cc42
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      discord/components.py

12
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:

Loading…
Cancel
Save