diff --git a/disco/api/client.py b/disco/api/client.py index 70345c8..09cbecc 100644 --- a/disco/api/client.py +++ b/disco/api/client.py @@ -165,7 +165,7 @@ class APIClient(LoggingClass): payload['content'] = content if embed: - payload['embed'] = embed.to_dict() + payload['embed'] = embed.to_dict(iso=True) if attachments: if len(attachments) > 1: @@ -197,7 +197,7 @@ class APIClient(LoggingClass): payload['content'] = content if embed: - payload['embed'] = embed.to_dict() + payload['embed'] = embed.to_dict(iso=True) r = self.http(Routes.CHANNELS_MESSAGES_MODIFY, dict(channel=channel, message=message), diff --git a/disco/types/message.py b/disco/types/message.py index ae03e5d..df0b280 100644 --- a/disco/types/message.py +++ b/disco/types/message.py @@ -4,6 +4,8 @@ import warnings import functools import unicodedata +from datetime import datetime as real_datetime + from disco.types.base import ( SlottedModel, Field, ListField, AutoDictField, snowflake, text, datetime, enum, cached_property, @@ -328,6 +330,14 @@ class MessageEmbed(SlottedModel): """ self.fields.append(MessageEmbedField(*args, **kwargs)) + def to_dict(self, iso=False): + data = super(MessageEmbed, self).to_dict() + # Ensure api calls don't try to send a non-json serializable datetime object. + if iso and isinstance(data.get("timestamp"), real_datetime): + data["timestamp"] = data["timestamp"].isoformat() + + return data + class MessageAttachment(SlottedModel): """