40
40
from .partial_emoji import PartialEmoji
41
41
from .calls import CallMessage
42
42
from .enums import MessageType , ChannelType , try_enum
43
- from .errors import InvalidArgument , ClientException , HTTPException
43
+ from .errors import InvalidArgument , ClientException , HTTPException , NotFound
44
44
from .embeds import Embed
45
- from .components import DecodeMessageComponents
45
+ from .components import DecodeMessageComponents , Button , DropdownMenue , ActionRow
46
46
from .member import Member
47
47
from .flags import MessageFlags
48
48
from .file import File
@@ -557,7 +557,7 @@ def __init__(self, *, state, channel, data):
557
557
self .reactions = [Reaction (message = self , data = d ) for d in data .get ('reactions' , [])]
558
558
self .attachments = [Attachment (data = a , state = self ._state ) for a in data ['attachments' ]]
559
559
self .embeds = [Embed .from_dict (a ) for a in data ['embeds' ]]
560
- self .components = data .get ('components' , None )
560
+ self .components = data .get ('components' , [] )
561
561
self .application = data .get ('application' )
562
562
self .activity = data .get ('activity' )
563
563
self .channel = channel
@@ -842,7 +842,7 @@ def clean_content(self):
842
842
.. note::
843
843
844
844
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`
846
846
respectively, along with this function.
847
847
"""
848
848
@@ -1053,6 +1053,8 @@ async def edit(self, **fields):
1053
1053
embed: Optional[:class:`Embed`]
1054
1054
The new embed to replace the original with.
1055
1055
Could be ``None`` to remove the embed.
1056
+ components: List[:class:`discord.ActionRow`]
1057
+ A list of :type:`discord.Actionrow`'s
1056
1058
suppress: :class:`bool`
1057
1059
Whether to suppress embeds for the message. This removes
1058
1060
all the embeds if set to ``True``. If set to ``False``
@@ -1090,15 +1092,23 @@ async def edit(self, **fields):
1090
1092
fields ['content' ] = str (content )
1091
1093
1092
1094
try :
1093
- embed = fields [ 'embed' ]
1095
+ embed = fields . pop ( 'embed' )
1094
1096
except KeyError :
1095
1097
pass
1096
1098
else :
1097
1099
if embed is not None :
1098
- fields ['embed ' ] = embed .to_dict ()
1100
+ fields ['embeds ' ] = [ embed .to_dict ()]
1099
1101
1100
1102
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' ]
1102
1112
except KeyError :
1103
1113
pass
1104
1114
else :
@@ -1111,7 +1121,7 @@ async def edit(self, **fields):
1111
1121
elif isinstance (component , DropdownMenue ):
1112
1122
components_list .append (component .to_dict ())
1113
1123
elif isinstance (component , ActionRow ):
1114
- components_list .append (component .sendable ())
1124
+ components_list .extend (component .sendable ())
1115
1125
fields ['components' ] = components_list
1116
1126
try :
1117
1127
suppress = fields .pop ('suppress' )
@@ -1136,10 +1146,31 @@ async def edit(self, **fields):
1136
1146
allowed_mentions = allowed_mentions .to_dict ()
1137
1147
fields ['allowed_mentions' ] = allowed_mentions
1138
1148
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 ))
1142
1170
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 )
1143
1174
if delete_after is not None :
1144
1175
await self .delete (delay = delete_after )
1145
1176
@@ -1548,6 +1579,8 @@ async def edit(self, **fields):
1548
1579
embed: Optional[:class:`Embed`]
1549
1580
The new embed to replace the original with.
1550
1581
Could be ``None`` to remove the embed.
1582
+ components: List[:class:`discord.ActionRow`]
1583
+ A list of :type:`discord.Actionrow`'s
1551
1584
suppress: :class:`bool`
1552
1585
Whether to suppress embeds for the message. This removes
1553
1586
all the embeds if set to ``True``. If set to ``False``
@@ -1590,21 +1623,36 @@ async def edit(self, **fields):
1590
1623
fields ['content' ] = str (content )
1591
1624
1592
1625
try :
1593
- embed = fields [ 'embed' ]
1626
+ embed = fields . pop ( 'embed' )
1594
1627
except KeyError :
1595
1628
pass
1596
1629
else :
1597
1630
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 ]
1599
1640
1600
1641
try :
1601
1642
components = fields ['components' ]
1602
1643
except KeyError :
1603
1644
pass
1604
1645
else :
1646
+ _components = []
1605
1647
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
1608
1656
1609
1657
try :
1610
1658
suppress = fields .pop ('suppress' )
@@ -1629,8 +1677,31 @@ async def edit(self, **fields):
1629
1677
allowed_mentions = allowed_mentions .to_dict ()
1630
1678
fields ['allowed_mentions' ] = allowed_mentions
1631
1679
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 )
1634
1705
1635
1706
if delete_after is not None :
1636
1707
await self .delete (delay = delete_after )
0 commit comments