Modals
class
TextStyles (IntEnum)
¶
An enumeration.
Source code in naff/models/discord/modal.py
class TextStyles(IntEnum):
SHORT = 1
PARAGRAPH = 2
attrs
class
InputText (InteractiveComponent)
¶
An input component for modals
Attr attributes:
Name | Type | Description |
---|---|---|
label |
str |
the label for this component |
style |
Union[naff.models.discord.modal.TextStyles, int] |
the Text Input Style for single or multiple lines input |
custom_id |
Optional[str] |
a developer-defined identifier for the input, max 100 characters |
placeholder |
Optional[str] |
custom placeholder text if the input is empty, max 100 characters |
value |
Optional[str] |
a pre-filled value for this component, max 4000 characters |
required |
bool |
whether this component is required to be filled, default true |
min_length |
Optional[int] |
the minimum input length for a text input, min 0, max 4000 |
max_length |
Optional[int] |
the maximum input length for a text input, min 1, max 4000. Must be more than min_length. |
Source code in naff/models/discord/modal.py
@define(kw_only=False)
class InputText(InteractiveComponent):
"""An input component for modals"""
type: Union[ComponentTypes, int] = field(
default=ComponentTypes.INPUT_TEXT, init=False, on_setattr=attrs.setters.frozen
)
label: str = field(validator=str_validator)
"""the label for this component"""
style: Union[TextStyles, int] = field()
"""the Text Input Style for single or multiple lines input"""
custom_id: Optional[str] = field(factory=lambda: str(uuid.uuid4()), validator=str_validator)
"""a developer-defined identifier for the input, max 100 characters"""
placeholder: Optional[str] = field(default=MISSING, validator=str_validator, kw_only=True)
"""custom placeholder text if the input is empty, max 100 characters"""
value: Optional[str] = field(default=MISSING, validator=str_validator, kw_only=True)
"""a pre-filled value for this component, max 4000 characters"""
required: bool = field(default=True, kw_only=True)
"""whether this component is required to be filled, default true"""
min_length: Optional[int] = field(default=MISSING, kw_only=True)
"""the minimum input length for a text input, min 0, max 4000"""
max_length: Optional[int] = field(default=MISSING, kw_only=True)
"""the maximum input length for a text input, min 1, max 4000. Must be more than min_length."""
inherited
method
update_from_dict(self, data)
¶
Updates object attribute(s) with new json data received from discord api.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Dict[str, Any] |
The json data received from discord api. |
required |
Returns:
Type | Description |
---|---|
~T |
The updated object class instance. |
Source code in naff/models/discord/modal.py
def update_from_dict(self: Type[const.T], data: Dict[str, Any]) -> const.T:
"""
Updates object attribute(s) with new json data received from discord api.
Args:
data: The json data received from discord api.
Returns:
The updated object class instance.
"""
data = self._process_dict(data)
for key, value in self._filter_kwargs(data, self._get_keys()).items():
# todo improve
setattr(self, key, value)
return self
inherited
method
to_dict(self)
¶
Exports object into dictionary representation, ready to be sent to discord api.
Returns:
Type | Description |
---|---|
Dict[str, Any] |
The exported dictionary. |
Source code in naff/models/discord/modal.py
def to_dict(self) -> Dict[str, Any]:
"""
Exports object into dictionary representation, ready to be sent to discord api.
Returns:
The exported dictionary.
"""
self._check_object()
return serializer.to_dict(self)
attrs
class
ShortText (InputText)
¶
A single line input component for modals
Attr attributes:
Name | Type | Description |
---|
Source code in naff/models/discord/modal.py
@define(kw_only=False)
class ShortText(InputText):
"""A single line input component for modals"""
style: Union[TextStyles, int] = field(default=TextStyles.SHORT, kw_only=True)
inherited
method
update_from_dict(self, data)
¶
Updates object attribute(s) with new json data received from discord api.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Dict[str, Any] |
The json data received from discord api. |
required |
Returns:
Type | Description |
---|---|
~T |
The updated object class instance. |
Source code in naff/models/discord/modal.py
def update_from_dict(self: Type[const.T], data: Dict[str, Any]) -> const.T:
"""
Updates object attribute(s) with new json data received from discord api.
Args:
data: The json data received from discord api.
Returns:
The updated object class instance.
"""
data = self._process_dict(data)
for key, value in self._filter_kwargs(data, self._get_keys()).items():
# todo improve
setattr(self, key, value)
return self
inherited
method
to_dict(self)
¶
Exports object into dictionary representation, ready to be sent to discord api.
Returns:
Type | Description |
---|---|
Dict[str, Any] |
The exported dictionary. |
Source code in naff/models/discord/modal.py
def to_dict(self) -> Dict[str, Any]:
"""
Exports object into dictionary representation, ready to be sent to discord api.
Returns:
The exported dictionary.
"""
self._check_object()
return serializer.to_dict(self)
attrs
class
ParagraphText (InputText)
¶
A multi line input component for modals
Attr attributes:
Name | Type | Description |
---|
Source code in naff/models/discord/modal.py
@define(kw_only=False)
class ParagraphText(InputText):
"""A multi line input component for modals"""
style: Union[TextStyles, int] = field(default=TextStyles.PARAGRAPH, kw_only=True)
inherited
method
update_from_dict(self, data)
¶
Updates object attribute(s) with new json data received from discord api.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Dict[str, Any] |
The json data received from discord api. |
required |
Returns:
Type | Description |
---|---|
~T |
The updated object class instance. |
Source code in naff/models/discord/modal.py
def update_from_dict(self: Type[const.T], data: Dict[str, Any]) -> const.T:
"""
Updates object attribute(s) with new json data received from discord api.
Args:
data: The json data received from discord api.
Returns:
The updated object class instance.
"""
data = self._process_dict(data)
for key, value in self._filter_kwargs(data, self._get_keys()).items():
# todo improve
setattr(self, key, value)
return self
inherited
method
to_dict(self)
¶
Exports object into dictionary representation, ready to be sent to discord api.
Returns:
Type | Description |
---|---|
Dict[str, Any] |
The exported dictionary. |
Source code in naff/models/discord/modal.py
def to_dict(self) -> Dict[str, Any]:
"""
Exports object into dictionary representation, ready to be sent to discord api.
Returns:
The exported dictionary.
"""
self._check_object()
return serializer.to_dict(self)
attrs
class
Modal (DictSerializationMixin)
¶
Form submission style component on discord
Attr attributes:
Name | Type | Description |
---|---|---|
title |
str |
the title of the popup modal, max 45 characters |
components |
List[naff.models.discord.modal.InputText] |
between 1 and 5 (inclusive) components that make up the modal |
custom_id |
Optional[str] |
a developer-defined identifier for the component, max 100 characters |
Source code in naff/models/discord/modal.py
@define(kw_only=False)
class Modal(DictSerializationMixin):
"""Form submission style component on discord"""
type: Union[CallbackTypes, int] = field(default=CallbackTypes.MODAL, init=False, on_setattr=attrs.setters.frozen)
title: str = field(validator=str_validator)
"""the title of the popup modal, max 45 characters"""
components: List[InputText] = field()
"""between 1 and 5 (inclusive) components that make up the modal"""
custom_id: Optional[str] = field(factory=lambda: str(uuid.uuid4()), validator=str_validator)
"""a developer-defined identifier for the component, max 100 characters"""
def __attrs_post_init__(self) -> None:
if self.custom_id is MISSING:
self.custom_id = str(uuid.uuid4())
def to_dict(self) -> dict:
data = super().to_dict()
components = [{"type": ComponentTypes.ACTION_ROW, "components": [c]} for c in data.get("components", [])]
return {
"type": data["type"],
"data": {"custom_id": data["custom_id"], "title": data["title"], "components": components},
}
method
to_dict(self)
¶
Exports object into dictionary representation, ready to be sent to discord api.
Returns:
Type | Description |
---|---|
dict |
The exported dictionary. |
Source code in naff/models/discord/modal.py
def to_dict(self) -> dict:
data = super().to_dict()
components = [{"type": ComponentTypes.ACTION_ROW, "components": [c]} for c in data.get("components", [])]
return {
"type": data["type"],
"data": {"custom_id": data["custom_id"], "title": data["title"], "components": components},
}
inherited
method
update_from_dict(self, data)
¶
Updates object attribute(s) with new json data received from discord api.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Dict[str, Any] |
The json data received from discord api. |
required |
Returns:
Type | Description |
---|---|
~T |
The updated object class instance. |
Source code in naff/models/discord/modal.py
def update_from_dict(self: Type[const.T], data: Dict[str, Any]) -> const.T:
"""
Updates object attribute(s) with new json data received from discord api.
Args:
data: The json data received from discord api.
Returns:
The updated object class instance.
"""
data = self._process_dict(data)
for key, value in self._filter_kwargs(data, self._get_keys()).items():
# todo improve
setattr(self, key, value)
return self