Skip to content
18 changes: 14 additions & 4 deletions interactions/client/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from ..base import get_logger
from ..utils.attrs_utils import ClientSerializerMixin, convert_int, define, field
from ..utils.missing import MISSING
from .enums import InteractionCallbackType, InteractionType
from .enums import ComponentType, InteractionCallbackType, InteractionType
from .models.command import Choice
from .models.component import ActionRow, Button, Modal, SelectMenu, _build_components
from .models.misc import InteractionData
Expand Down Expand Up @@ -738,7 +738,17 @@ def custom_id(self) -> Optional[str]:

@property
def label(self) -> Optional[str]:
"""
The label of the interacted component.
:rtype: Optional[str]
"""
if not self.data.component_type == ComponentType.BUTTON:
return
if self.message is None:
return
if self.message.components is None:
return
for action_row in self.message.components:
for component in action_row["components"]:
if component["custom_id"] == self.custom_id and component["type"] == 2:
return component.get("label")
for component in action_row.components:
if component.custom_id == self.custom_id:
return component.label