Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ These changes are available on the `master` branch, but have not yet been releas

- Support for **Python 3.14**.
([#2948](https://github.com/Pycord-Development/pycord/pull/2948))
- Added `ComponentLimits` and `EmbedLimits` enums for Discord API constraints.
([#3217](https://github.com/Pycord-Development/pycord/pull/3217))

### Changed

Expand Down
99 changes: 87 additions & 12 deletions discord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@
"SelectDefaultValueType",
"ApplicationEventWebhookStatus",
"InviteTargetUsersJobStatusCode",
"ComponentLimits",
"EmbedLimits",
)


Expand All @@ -96,21 +98,17 @@ def _create_value_cls(name, comparable):
cls.__repr__ = lambda self: f"<{name}.{self.name}: {self.value!r}>"
cls.__str__ = lambda self: f"{name}.{self.name}"
if comparable:
cls.__le__ = (
lambda self, other: isinstance(other, self.__class__)
and self.value <= other.value
cls.__le__ = lambda self, other: (
isinstance(other, self.__class__) and self.value <= other.value
)
cls.__ge__ = (
lambda self, other: isinstance(other, self.__class__)
and self.value >= other.value
cls.__ge__ = lambda self, other: (
isinstance(other, self.__class__) and self.value >= other.value
)
cls.__lt__ = (
lambda self, other: isinstance(other, self.__class__)
and self.value < other.value
cls.__lt__ = lambda self, other: (
isinstance(other, self.__class__) and self.value < other.value
)
cls.__gt__ = (
lambda self, other: isinstance(other, self.__class__)
and self.value > other.value
cls.__gt__ = lambda self, other: (
isinstance(other, self.__class__) and self.value > other.value
)
return cls

Expand Down Expand Up @@ -1212,6 +1210,83 @@ class InviteTargetUsersJobStatusCode(Enum):
failed = 3


class ComponentLimits(Enum):
Comment thread
Lumabots marked this conversation as resolved.
Comment thread
Lumabots marked this conversation as resolved.
# View constraints
view_children_max = 40

# ActionRow constraints
action_row_children_max = 5

# Button constraints
button_label_max = 80

# Container constraints
container_children_max = float("inf") # No limit
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only non-int member of the enum, which makes it inconsistent with all other members.

Suggested change
container_children_max = float("inf") # No limit
container_children_max = -1 # No limit


# MediaGallery constraints
media_gallery_items_min = 1
media_gallery_items_max = 10

# MediaGalleryItem constraints
media_gallery_item_description_max = 256
Comment thread
Lumabots marked this conversation as resolved.

# Select constraints
select_placeholder_max = 150
select_min_value_max = 25
select_max_value_max = 25
Comment on lines +1235 to +1238
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are not yet documented in docs/enums.rst

select_options_max = 25

# Select option constraints
select_option_label_max = 100
select_option_value_max = 100
select_option_description_max = 100

# Section constraints
section_accessory_max = 1
section_children_min = 1
section_children_max = 3

# TextInput constraints
text_input_max_count = 5
text_input_label_max = 45
text_input_placeholder_max = 100
text_input_min_length_max = 4000
text_input_max_length_max = 4000
text_input_value_max = 4000

# TextDisplay constraints
text_display_content_max = 4000

# Thumbnail constraints
thumbnail_description_max = 256

# Custom ID constraints
custom_id_min = 1
custom_id_max = 100


class EmbedLimits(Enum):
# Embed field constraints
fields_max = 25

# Field title/name constraints
field_name_max = 256

# Field value constraints
field_value_max = 1024

# Embed description constraints
description_max = 4096

# Embed footer constraints
footer_text_max = 2048

# Embed author constraints
author_name_max = 256
title_max = 256
total_max = 6000


T = TypeVar("T")


Expand Down
156 changes: 156 additions & 0 deletions docs/api/enums.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2682,6 +2682,162 @@ of :class:`enum.Enum`.
.. attribute:: disabled_by_discord
The application webhook is disabled by Discord.

.. class:: ComponentLimits

Represents the limits for various Discord UI components.

.. versionadded:: 2.8.1

.. attribute:: view_children_max

The maximum number of children a View can have (40).

.. attribute:: action_row_children_max

The maximum number of children an ActionRow can have (5).

.. attribute:: button_label_max

The maximum length of a button label (80).

.. attribute:: container_children_max

The maximum number of children a Container can have (no limit).

.. attribute:: media_gallery_items_min

The minimum number of items in a MediaGallery (1).

.. attribute:: media_gallery_items_max

The maximum number of items in a MediaGallery (10).

.. attribute:: media_gallery_item_description_max

The maximum length of a MediaGalleryItem description (256).

.. attribute:: select_placeholder_max

The maximum length of a select placeholder (150).

.. attribute:: select_min_value_max

The maximum value for select's minimum value constraint (25).

.. attribute:: select_max_value_max

The maximum value for select's maximum value constraint (25).

.. attribute:: select_options_max

The maximum number of options in a select menu (25).

.. attribute:: select_option_label_max

The maximum length of a select option label (100).

.. attribute:: select_option_value_max

The maximum length of a select option value (100).

.. attribute:: select_option_description_max

The maximum length of a select option description (100).

.. attribute:: section_accessory_max

The maximum number of accessories in a Section (1).

.. attribute:: section_children_min

The minimum number of children in a Section (1).

.. attribute:: section_children_max

The maximum number of children in a Section (3).

.. attribute:: text_input_max_count

The maximum number of TextInputs in a modal (5).

.. attribute:: text_input_label_max

The maximum length of a TextInput label (45).

.. attribute:: text_input_placeholder_max

The maximum length of a TextInput placeholder (100).

.. attribute:: text_input_min_length_max

The maximum value for TextInput's minimum length (4000).

.. attribute:: text_input_max_length_max

The maximum value for TextInput's maximum length (4000).

.. attribute:: text_input_value_max

The maximum length of a TextInput value (4000).

.. attribute:: text_display_content_max

The maximum length of TextDisplay content (4000).

.. attribute:: thumbnail_description_max

The maximum length of a Thumbnail description (256).

.. attribute:: custom_id_min

The minimum length of a custom ID (1).

.. attribute:: custom_id_max

The maximum length of a custom ID (100).

.. class:: EmbedLimits

Represents the limits for Discord embeds.
Comment thread
Lumabots marked this conversation as resolved.

.. note::

The sum of all characters in an embed must be ≤ 6000.

.. versionadded:: 2.8.1

.. attribute:: fields_max

The maximum number of embed fields (25).

.. attribute:: field_name_max

The maximum length of a field name/title (256).

.. attribute:: field_value_max

The maximum length of a field value (1024).

.. attribute:: description_max

The maximum length of an embed description (4096).

.. attribute:: footer_text_max

The maximum length of an embed footer text (2048).

.. attribute:: author_name_max

The maximum length of an embed author name (256).

.. attribute:: title_max

The maximum length of an embed title (256).

.. attribute:: total_max

The maximum total character limit for an entire embed (6000).

.. class:: TeamRole
Represents a app team role.

Expand Down
Loading