Skip to content

Modals

Modal

Source code in interactions/models/discord/modal.py
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
class Modal:
    def __init__(
        self,
        *components: InputText,
        title: str,
        custom_id: Optional[str] = None,
    ) -> None:
        self.title: str = title
        self.components: list[InputText] = list(components)
        self.custom_id: str = custom_id or str(uuid.uuid4())

        self.type = CallbackType.MODAL

    def to_dict(self) -> discord_typings.ModalInteractionData:
        return {
            "type": self.type,
            "data": {
                "title": self.title,
                "custom_id": self.custom_id,
                "components": [
                    {
                        "type": ComponentType.ACTION_ROW,
                        "components": [c.to_dict() if hasattr(c, "to_dict") else c],
                    }
                    for c in self.components
                ],
            },
        }

    def add_components(self, *components: InputText) -> None:
        """
        Add components to the modal.

        Args:
            *components: The components to add.

        """
        if len(components) == 1 and isinstance(components[0], (list, tuple)):
            components = components[0]
        self.components.extend(components)

add_components(*components)

Add components to the modal.

Parameters:

Name Type Description Default
*components InputText

The components to add.

()
Source code in interactions/models/discord/modal.py
159
160
161
162
163
164
165
166
167
168
169
def add_components(self, *components: InputText) -> None:
    """
    Add components to the modal.

    Args:
        *components: The components to add.

    """
    if len(components) == 1 and isinstance(components[0], (list, tuple)):
        components = components[0]
    self.components.extend(components)