Skip to content

Commit 8873ada

Browse files
committed
fix: Fix timestamp assignment on Embed objects on non-declaration.
1 parent ea95732 commit 8873ada

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

interactions/api/models/message.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,11 +1026,16 @@ class Embed(DictSerializerMixin):
10261026

10271027
def __init__(self, **kwargs):
10281028
super().__init__(**kwargs)
1029-
self.timestamp = (
1030-
datetime.fromisoformat(self._json.get("timestamp"))
1031-
if self._json.get("timestamp")
1032-
else datetime.utcnow()
1033-
)
1029+
if self._json.get("timestamp"):
1030+
if isinstance(self._json.get("timestamp"), str):
1031+
self.timestamp = datetime.fromisoformat(
1032+
self._json.get("timestamp")
1033+
) # readability on non `_json` attr.
1034+
elif isinstance(self._json.get("timestamp"), datetime):
1035+
self._json["timestamp"] = str(
1036+
self._json.get("timestamp")
1037+
) # converts to isoformat for API.
1038+
10341039
self.footer = EmbedFooter(**self.footer) if isinstance(self.footer, dict) else self.footer
10351040
self.image = EmbedImageStruct(**self.image) if isinstance(self.image, dict) else self.image
10361041
self.thumbnail = (
@@ -1048,7 +1053,6 @@ def __init__(self, **kwargs):
10481053
if self._json.get("fields")
10491054
else None
10501055
)
1051-
10521056
# (Complete partial fix.)
10531057
# The issue seems to be that this itself is not updating
10541058
# JSON result correctly. After numerous attempts I seem to

0 commit comments

Comments
 (0)