From 66f3548f3a84a1272c5afa6c6abfff799269adf4 Mon Sep 17 00:00:00 2001 From: dolfies Date: Fri, 28 Feb 2025 18:00:33 -0500 Subject: [PATCH] Add defaults for message object parsing --- discord/message.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/discord/message.py b/discord/message.py index 05b0da183..e7752fb8d 100644 --- a/discord/message.py +++ b/discord/message.py @@ -2194,15 +2194,15 @@ class Message(PartialMessage, Hashable): self._state: ConnectionState = state self.webhook_id: Optional[int] = utils._get_as_snowflake(data, 'webhook_id') self.reactions: List[Reaction] = [Reaction(message=self, data=d) for d in data.get('reactions', [])] - self.attachments: List[Attachment] = [Attachment(data=a, state=self._state) for a in data['attachments']] - self.embeds: List[Embed] = [Embed.from_dict(a) for a in data['embeds']] + self.attachments: List[Attachment] = [Attachment(data=a, state=self._state) for a in data.get('attachments', [])] + self.embeds: List[Embed] = [Embed.from_dict(a) for a in data.get('embeds', [])] self.activity: Optional[MessageActivityPayload] = data.get('activity') - self._edited_timestamp: Optional[datetime.datetime] = utils.parse_time(data['edited_timestamp']) + self._edited_timestamp: Optional[datetime.datetime] = utils.parse_time(data.get('edited_timestamp')) self.type: MessageType = try_enum(MessageType, data['type']) - self.pinned: bool = data['pinned'] + self.pinned: bool = data.get('pinned', False) self.flags: MessageFlags = MessageFlags._from_value(data.get('flags', 0)) - self.mention_everyone: bool = data['mention_everyone'] - self.tts: bool = data['tts'] + self.mention_everyone: bool = data.get('mention_everyone', False) + self.tts: bool = data.get('tts', False) self.content: str = data['content'] self.nonce: Optional[Union[int, str]] = data.get('nonce') self.position: Optional[int] = data.get('position')