aboutsummaryrefslogtreecommitdiff
path: root/discord/message.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2019-02-27 06:23:08 -0500
committerRapptz <[email protected]>2019-02-27 06:23:08 -0500
commit7240d170c1bfe9851faaa2d17f00e6bc195108b3 (patch)
treec927877dffb4edcad7496422cdb2db4c1ea128d0 /discord/message.py
parent[commands] Add support for stacking Cog.listener decorator. (diff)
downloaddiscord.py-7240d170c1bfe9851faaa2d17f00e6bc195108b3.tar.xz
discord.py-7240d170c1bfe9851faaa2d17f00e6bc195108b3.zip
Update Member.joined_at on MESSAGE_CREATE and document it can be None.
Fixes #1638
Diffstat (limited to 'discord/message.py')
-rw-r--r--discord/message.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/discord/message.py b/discord/message.py
index 2a41c2fa..ca7b9ee3 100644
--- a/discord/message.py
+++ b/discord/message.py
@@ -35,6 +35,7 @@ from .calls import CallMessage
from .enums import MessageType, try_enum
from .errors import InvalidArgument, ClientException, HTTPException
from .embeds import Embed
+from .member import Member
class Attachment:
"""Represents an attachment from Discord.
@@ -277,7 +278,7 @@ class Message:
self._try_patch(data, 'embeds', lambda x: list(map(Embed.from_data, x)))
self._try_patch(data, 'nonce')
- for handler in ('author', 'mentions', 'mention_roles', 'call'):
+ for handler in ('author', 'member', 'mentions', 'mention_roles', 'call'):
try:
getattr(self, '_handle_%s' % handler)(data[handler])
except KeyError:
@@ -298,6 +299,20 @@ class Message:
if found is not None:
self.author = found
+ def _handle_member(self, member):
+ # The gateway now gives us full Member objects sometimes with the following keys
+ # deaf, mute, joined_at, roles
+ # For the sake of performance I'm going to assume that the only
+ # field that needs *updating* would be the joined_at field.
+ # If there is no Member object (for some strange reason), then we can upgrade
+ # ourselves to a more "partial" member object.
+ author = self.author
+ try:
+ if author.joined_at is None:
+ author.joined_at = utils.parse_time(member.get('joined_at'))
+ except AttributeError:
+ self.author = Member._from_message(message=self, data=member)
+
def _handle_mentions(self, mentions):
self.mentions = []
if self.guild is None: