Add content_length method to LayoutView and container items

This commit is contained in:
Rapptz
2025-08-18 14:33:15 -04:00
parent e00bb0b0f3
commit f08c042217
4 changed files with 27 additions and 0 deletions

View File

@ -327,6 +327,15 @@ class BaseView:
"""List[:class:`Item`]: The list of children attached to this view."""
return self._children.copy()
def content_length(self) -> int:
""":class:`int`: Returns the total length of all text content in the view's items.
A view is allowed to have a maximum of 4000 display characters across all its items.
"""
from .text_display import TextDisplay
return sum(len(item.content) for item in self.walk_children() if isinstance(item, TextDisplay))
@classmethod
def from_message(cls, message: Message, /, *, timeout: Optional[float] = 180.0) -> Union[View, LayoutView]:
"""Converts a message's components into a :class:`View`