4040from .partial_emoji import PartialEmoji
4141from .calls import CallMessage
4242from .enums import MessageType , ChannelType , try_enum
43- from .errors import InvalidArgument , ClientException , HTTPException
43+ from .errors import InvalidArgument , ClientException , HTTPException , NotFound
4444from .embeds import Embed
45- from .components import DecodeMessageComponents
45+ from .components import DecodeMessageComponents , Button , DropdownMenue , ActionRow
4646from .member import Member
4747from .flags import MessageFlags
4848from .file import File
@@ -557,7 +557,7 @@ def __init__(self, *, state, channel, data):
557557 self .reactions = [Reaction (message = self , data = d ) for d in data .get ('reactions' , [])]
558558 self .attachments = [Attachment (data = a , state = self ._state ) for a in data ['attachments' ]]
559559 self .embeds = [Embed .from_dict (a ) for a in data ['embeds' ]]
560- self .components = data .get ('components' , None )
560+ self .components = data .get ('components' , [] )
561561 self .application = data .get ('application' )
562562 self .activity = data .get ('activity' )
563563 self .channel = channel
@@ -842,7 +842,7 @@ def clean_content(self):
842842 .. note::
843843
844844 This *does not* affect markdown. If you want to escape
845- or remove markdown then use :func:`utils.escape_markdown` or :func:`utils.remove_markdown`
845+ or remove markdown then use :func:`utils.escape_markdown` or :func:`utils.remove_markdown`
846846 respectively, along with this function.
847847 """
848848
@@ -1053,6 +1053,8 @@ async def edit(self, **fields):
10531053 embed: Optional[:class:`Embed`]
10541054 The new embed to replace the original with.
10551055 Could be ``None`` to remove the embed.
1056+ components: List[:class:`discord.ActionRow`]
1057+ A list of :type:`discord.Actionrow`'s
10561058 suppress: :class:`bool`
10571059 Whether to suppress embeds for the message. This removes
10581060 all the embeds if set to ``True``. If set to ``False``
@@ -1090,15 +1092,23 @@ async def edit(self, **fields):
10901092 fields ['content' ] = str (content )
10911093
10921094 try :
1093- embed = fields [ 'embed' ]
1095+ embed = fields . pop ( 'embed' )
10941096 except KeyError :
10951097 pass
10961098 else :
10971099 if embed is not None :
1098- fields ['embed ' ] = embed .to_dict ()
1100+ fields ['embeds ' ] = [ embed .to_dict ()]
10991101
11001102 try :
1101- components = fields .get ('components' )
1103+ embeds = fields ['embeds' ]
1104+ except KeyError :
1105+ pass
1106+ else :
1107+ if embeds is not None and not embed :
1108+ fields ['embeds' ] = [e .to_dict () for e in embeds ]
1109+
1110+ try :
1111+ components = fields ['components' ]
11021112 except KeyError :
11031113 pass
11041114 else :
@@ -1111,7 +1121,7 @@ async def edit(self, **fields):
11111121 elif isinstance (component , DropdownMenue ):
11121122 components_list .append (component .to_dict ())
11131123 elif isinstance (component , ActionRow ):
1114- components_list .append (component .sendable ())
1124+ components_list .extend (component .sendable ())
11151125 fields ['components' ] = components_list
11161126 try :
11171127 suppress = fields .pop ('suppress' )
@@ -1136,10 +1146,31 @@ async def edit(self, **fields):
11361146 allowed_mentions = allowed_mentions .to_dict ()
11371147 fields ['allowed_mentions' ] = allowed_mentions
11381148
1139- if fields :
1140- data = await self ._state .http .edit_message (self .channel .id , self .id , ** fields )
1141- self ._update (data )
1149+ is_interaction_responce = fields .pop ('__is_interaction_responce' , None )
1150+ if is_interaction_responce is True :
1151+ deffered = fields .pop ('__deffered' , False )
1152+ use_webhook = fields .pop ('__use_webhook' , False )
1153+ interaction_id = fields .pop ('__interaction_id' , None )
1154+ interaction_token = fields .pop ('__interaction_token' , None )
1155+ application_id = fields .pop ('__application_id' , None )
1156+ payload = {'data' : fields }
1157+ if not deffered is True :
1158+ payload ['type' ] = 7
1159+ if payload :
1160+ try :
1161+ data = await self ._state .http .edit_interaction_response (use_webhook = use_webhook ,
1162+ interaction_id = interaction_id ,
1163+ token = interaction_token ,
1164+ application_id = application_id ,
1165+ fields = payload )
1166+ except NotFound :
1167+ raise NotFound ("You have already responded to this Interaction!" )
1168+ else :
1169+ self ._update (dict (data ))
11421170
1171+ elif is_interaction_responce is None :
1172+ payload = await self ._state .http .edit_message (self .channel .id , self .id , ** fields )
1173+ self ._update (payload )
11431174 if delete_after is not None :
11441175 await self .delete (delay = delete_after )
11451176
@@ -1548,6 +1579,8 @@ async def edit(self, **fields):
15481579 embed: Optional[:class:`Embed`]
15491580 The new embed to replace the original with.
15501581 Could be ``None`` to remove the embed.
1582+ components: List[:class:`discord.ActionRow`]
1583+ A list of :type:`discord.Actionrow`'s
15511584 suppress: :class:`bool`
15521585 Whether to suppress embeds for the message. This removes
15531586 all the embeds if set to ``True``. If set to ``False``
@@ -1590,21 +1623,36 @@ async def edit(self, **fields):
15901623 fields ['content' ] = str (content )
15911624
15921625 try :
1593- embed = fields [ 'embed' ]
1626+ embed = fields . pop ( 'embed' )
15941627 except KeyError :
15951628 pass
15961629 else :
15971630 if embed is not None :
1598- fields ['embed' ] = embed .to_dict ()
1631+ fields ['embeds' ] = [embed .to_dict ()]
1632+
1633+ try :
1634+ embeds = fields ['embeds' ]
1635+ except KeyError :
1636+ pass
1637+ else :
1638+ if embeds is not None and not embed :
1639+ fields ['embeds' ] = [e .to_dict () for e in embeds ]
15991640
16001641 try :
16011642 components = fields ['components' ]
16021643 except KeyError :
16031644 pass
16041645 else :
1646+ _components = []
16051647 if components is not None :
1606- #print(components)
1607- fields ['components' ] = components .to_dict ()
1648+ for component in ([components ] if not type (components ) == list else components ):
1649+ if isinstance (component , Button ):
1650+ _components .append (component .to_dict ())
1651+ elif isinstance (component , DropdownMenue ):
1652+ _components .append (component .to_dict ())
1653+ elif isinstance (component , ActionRow ):
1654+ _components .extend (component .sendable ())
1655+ fields ['components' ] = _components
16081656
16091657 try :
16101658 suppress = fields .pop ('suppress' )
@@ -1629,8 +1677,31 @@ async def edit(self, **fields):
16291677 allowed_mentions = allowed_mentions .to_dict ()
16301678 fields ['allowed_mentions' ] = allowed_mentions
16311679
1632- if fields :
1633- data = await self ._state .http .edit_message (self .channel .id , self .id , ** fields )
1680+ is_interaction_responce = fields .pop ('__is_interaction_responce' , None )
1681+ if is_interaction_responce is True :
1682+ deffered = fields .pop ('__deffered' , False )
1683+ use_webhook = fields .pop ('__use_webhook' , False )
1684+ interaction_id = fields .pop ('__interaction_id' , None )
1685+ interaction_token = fields .pop ('__interaction_token' , None )
1686+ application_id = fields .pop ('__application_id' , None )
1687+ payload = {'data' : fields }
1688+ if not deffered is True :
1689+ payload ['type' ] = 7
1690+ if payload :
1691+ try :
1692+ r = await self ._state .http .edit_interaction_response (use_webhook = use_webhook ,
1693+ interaction_id = interaction_id ,
1694+ token = interaction_token ,
1695+ application_id = application_id ,
1696+ fields = payload )
1697+ except NotFound :
1698+ raise NotFound (r , "You have already responded to this Interaction!" )
1699+ else :
1700+ self ._update (payload ['data' ])
1701+
1702+ elif is_interaction_responce is None :
1703+ payload = await self ._state .http .edit_message (self .channel .id , self .id , ** fields )
1704+ self ._update (payload )
16341705
16351706 if delete_after is not None :
16361707 await self .delete (delay = delete_after )
0 commit comments