def __init__(self, *, state: ConnectionState, channel: MessageableChannel, data: MessagePayload) -> None:
    self.channel: MessageableChannel = channel
    self.id: int = int(data['id'])
    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.application: Optional[MessageApplicationPayload] = data.get('application')
    self.activity: Optional[MessageActivityPayload] = data.get('activity')
    self.channel: MessageableChannel = channel
    self._edited_timestamp: Optional[datetime.datetime] = utils.parse_time(data['edited_timestamp'])
    self.type: MessageType = try_enum(MessageType, data['type'])
    self.pinned: bool = data['pinned']
    self.flags: MessageFlags = MessageFlags._from_value(data.get('flags', 0))
    self.mention_everyone: bool = data['mention_everyone']
    self.tts: bool = data['tts']
    self.content: str = data['content']
    self.nonce: Optional[Union[(int, str)]] = data.get('nonce')
    self.stickers: List[StickerItem] = [StickerItem(data=d, state=state) for d in data.get('sticker_items', [])]
    self.components: List[Component] = [_component_factory(d) for d in data.get('components', [])]
    try:
        self.guild = channel.guild
    except AttributeError:
        self.guild = state._get_guild(utils._get_as_snowflake(data, 'guild_id'))
    self.interaction: Optional[MessageInteraction] = None
    try:
        interaction = data['interaction']
    except KeyError:
        pass
    else:
        self.interaction = MessageInteraction(state=state, guild=self.guild, data=interaction)
    try:
        ref = data['message_reference']
    except KeyError:
        self.reference = None
    else:
        self.reference = ref = MessageReference.with_state(state, ref)
        try:
            resolved = data['referenced_message']
        except KeyError:
            pass
        else:
            if (resolved is None):
                ref.resolved = DeletedReferencedMessage(ref)
            else:
                if (ref.channel_id == channel.id):
                    chan = channel
                elif (isinstance(channel, Thread) and (channel.parent_id == ref.channel_id)):
                    chan = channel
                else:
                    (chan, _) = state._get_guild_channel(resolved, ref.guild_id)
                ref.resolved = self.__class__(channel=chan, data=resolved, state=state)
    for handler in ('author', 'member', 'mentions', 'mention_roles'):
        try:
            getattr(self, f'_handle_{handler}')(data[handler])
        except KeyError:
            continue
def __init__(self, *, state: ConnectionState, channel: MessageableChannel, data: MessagePayload) -> None:
    self.channel: MessageableChannel = channel
    self.id: int = int(data['id'])
    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.application: Optional[MessageApplicationPayload] = data.get('application')
    self.activity: Optional[MessageActivityPayload] = data.get('activity')
    self.channel: MessageableChannel = channel
    self._edited_timestamp: Optional[datetime.datetime] = utils.parse_time(data['edited_timestamp'])
    self.type: MessageType = try_enum(MessageType, data['type'])
    self.pinned: bool = data['pinned']
    self.flags: MessageFlags = MessageFlags._from_value(data.get('flags', 0))
    self.mention_everyone: bool = data['mention_everyone']
    self.tts: bool = data['tts']
    self.content: str = data['content']
    self.nonce: Optional[Union[(int, str)]] = data.get('nonce')
    self.stickers: List[StickerItem] = [StickerItem(data=d, state=state) for d in data.get('sticker_items', [])]
    self.components: List[Component] = [_component_factory(d) for d in data.get('components', [])]
    try:
        self.guild = channel.guild
    except AttributeError:
        self.guild = state._get_guild(utils._get_as_snowflake(data, 'guild_id'))
    self.interaction: Optional[MessageInteraction] = None
    try:
        interaction = data['interaction']
    except KeyError:
        pass
    else:
        self.interaction = MessageInteraction(state=state, guild=self.guild, data=interaction)
    try:
        ref = data['message_reference']
    except KeyError:
        self.reference = None
    else:
        self.reference = ref = MessageReference.with_state(state, ref)
        try:
            resolved = data['referenced_message']
        except KeyError:
            pass
        else:
            if (resolved is None):
                ref.resolved = DeletedReferencedMessage(ref)
            else:
                if (ref.channel_id == channel.id):
                    chan = channel
                elif (isinstance(channel, Thread) and (channel.parent_id == ref.channel_id)):
                    chan = channel
                else:
                    (chan, _) = state._get_guild_channel(resolved, ref.guild_id)
                ref.resolved = self.__class__(channel=chan, data=resolved, state=state)
    for handler in ('author', 'member', 'mentions', 'mention_roles'):
        try:
            getattr(self, f'_handle_{handler}')(data[handler])
        except KeyError:
            continue