4444from typing_extensions import Self
4545
4646from . import utils
47- from .channel import ThreadChannel
4847from .reaction import Reaction
4948from .emoji import Emoji
5049from .partial_emoji import PartialEmoji
8382
8483__all__ = (
8584 'Attachment' ,
85+ 'MessageInteraction' ,
8686 'Message' ,
8787 'PartialMessage' ,
8888 'MessageReference' ,
@@ -641,6 +641,8 @@ class Message(Hashable):
641641 A list of stickers given to the message.
642642
643643 .. versionadded:: 1.6
644+ interaction: Optional[:class:`MessageInteraction`]
645+ The interaction associated with this message if any.
644646 """
645647
646648 __slots__ = ('_edited_timestamp' , 'tts' , 'content' , 'channel' , 'webhook_id' ,
@@ -661,6 +663,8 @@ def __init__(self, *, state: ConnectionState, channel, data: MessagePayload):
661663 self .components : List [ActionRow ] = [ActionRow .from_dict (d ) for d in data .get ('components' , [])]
662664 self .application = data .get ('application' ) # TODO: make this a class
663665 self .activity = data .get ('activity' ) # TODO: make this a class
666+ interaction = data .get ('interaction' )
667+ self .interaction : Optional [MessageInteraction ] = MessageInteraction (state = state , data = data ) if interaction else None
664668 self .channel : Messageable = channel
665669 self ._edited_timestamp : datetime = utils .parse_time (data ['edited_timestamp' ])
666670 self .type : MessageType = try_enum (MessageType , data ['type' ])
@@ -693,7 +697,7 @@ def __init__(self, *, state: ConnectionState, channel, data: MessagePayload):
693697
694698 ref .resolved = self .__class__ (channel = chan , data = resolved , state = state )
695699
696- for handler in ('author' , 'member' , 'mentions' , 'mention_roles' , 'flags' , 'interaction' , ' thread' ):
700+ for handler in ('author' , 'member' , 'mentions' , 'mention_roles' , 'flags' , 'thread' ):
697701 try :
698702 getattr (self , '_handle_%s' % handler )(data [handler ])
699703 except KeyError :
@@ -816,7 +820,7 @@ def _handle_embeds(self, value):
816820 self .embeds : List [Embed ] = [Embed .from_dict (data ) for data in value ]
817821
818822 def _handle_interaction (self , value ):
819- self .interaction = value # TODO: implement interaction-model for message
823+ self .interaction = MessageInteraction ( state = self . _state , data = value )
820824
821825 def _handle_thread (self , value ):
822826 thread = self .guild .get_channel (self .id )
0 commit comments