diff --git a/disnake/message.py b/disnake/message.py index ebb470f76e..5620a1b349 100644 --- a/disnake/message.py +++ b/disnake/message.py @@ -324,15 +324,19 @@ def __init__(self, *, data: AttachmentPayload, state: ConnectionState) -> None: b64decode(waveform_data) if (waveform_data := data.get("waveform")) else None ) _params = urlparse(self.url) - self._ex = parse_qs(_params.query)["ex"][0] + self._ex = parse_qs(_params.query).get("ex") self._flags: int = data.get("flags", 0) - def expires_at(self) -> datetime.datetime: + def expires_at(self) -> Optional[datetime.datetime]: """The date when this attachment will expire. + ``None`` if the ``ex`` param is not present in :attr:`.Attachment.url`. - :return type: :class:`datetime.datetime` + :return type: Optional[:class:`datetime.datetime`] """ - timestamp = int(self._ex, 16) + if not self._ex: + return + + timestamp = int(self._ex[0], 16) return datetime.datetime.fromtimestamp(timestamp, tz=datetime.timezone.utc) def is_expired(self) -> bool: @@ -340,7 +344,11 @@ def is_expired(self) -> bool: :return type: :class:`bool` """ - return utils.utcnow() >= self.expires_at() + ex = self.expires_at() + if not ex: + return False + + return utils.utcnow() >= ex def is_spoiler(self) -> bool: """Whether this attachment contains a spoiler.