@@ -1814,8 +1814,6 @@ async def edit(self, **fields: Any) -> Optional[Message]:
1814
1814
1815
1815
Edits the message.
1816
1816
1817
- The content must be able to be transformed into a string via ``str(content)``.
1818
-
1819
1817
.. versionchanged:: 1.7
1820
1818
:class:`discord.Message` is returned instead of ``None`` if an edit took place.
1821
1819
@@ -1824,9 +1822,13 @@ async def edit(self, **fields: Any) -> Optional[Message]:
1824
1822
content: Optional[:class:`str`]
1825
1823
The new content to replace the message with.
1826
1824
Could be ``None`` to remove the content.
1827
- embed: Optional[:class:`Embed`]
1825
+ embed: Optional[:class:`~discord. Embed`]
1828
1826
The new embed to replace the original with.
1829
1827
Could be ``None`` to remove the embed.
1828
+ embeds: Optional[List[:class:`~discord.Embed`]]
1829
+ A list of embeds to upload. Must be a maximum of 10.
1830
+
1831
+ .. versionadded:: 2.0
1830
1832
suppress: :class:`bool`
1831
1833
Whether to suppress embeds for the message. This removes
1832
1834
all the embeds if set to ``True``. If set to ``False``
@@ -1865,53 +1867,43 @@ async def edit(self, **fields: Any) -> Optional[Message]:
1865
1867
The message that was edited.
1866
1868
"""
1867
1869
1868
- try :
1869
- content = fields ["content" ]
1870
- except KeyError :
1871
- pass
1872
- else :
1873
- if content is not None :
1874
- fields ["content" ] = str (content )
1870
+ content = fields .pop ("content" , MISSING )
1871
+ if content is not MISSING :
1872
+ fields ["content" ] = str (content )
1875
1873
1876
- try :
1877
- embed = fields ["embed" ]
1878
- except KeyError :
1879
- pass
1880
- else :
1881
- if embed is not None :
1882
- fields ["embed" ] = embed .to_dict ()
1874
+ embed = fields .pop ("embed" , MISSING )
1875
+ embeds = fields .pop ("embeds" , MISSING )
1883
1876
1884
- try :
1885
- suppress : bool = fields .pop ("suppress" )
1886
- except KeyError :
1887
- pass
1888
- else :
1889
- flags = MessageFlags ._from_value (0 )
1890
- flags .suppress_embeds = suppress
1891
- fields ["flags" ] = flags .value
1877
+ if embed is not MISSING and embeds is not MISSING :
1878
+ raise InvalidArgument ("Cannot pass both embed and embeds parameters." )
1879
+
1880
+ if embed is not MISSING :
1881
+ fields ["embeds" ] = [embed .to_dict ()]
1882
+
1883
+ if embeds is not MISSING :
1884
+ fields ["embeds" ] = [embed .to_dict () for embed in embeds ]
1885
+
1886
+ suppress = fields .pop ("suppress" , False )
1887
+ flags = MessageFlags ._from_value (0 )
1888
+ flags .suppress_embeds = suppress
1889
+ fields ["flags" ] = flags .value
1892
1890
1893
1891
delete_after = fields .pop ("delete_after" , None )
1894
1892
1895
- try :
1896
- allowed_mentions = fields .pop ("allowed_mentions" )
1897
- except KeyError :
1898
- pass
1893
+ allowed_mentions = fields .get ("allowed_mentions" , MISSING )
1894
+ if allowed_mentions is not MISSING :
1895
+ if self ._state .allowed_mentions is not None :
1896
+ allowed_mentions = self ._state .allowed_mentions .merge (allowed_mentions ).to_dict ()
1897
+ else :
1898
+ allowed_mentions = allowed_mentions .to_dict ()
1899
+ fields ["allowed_mentions" ] = allowed_mentions
1899
1900
else :
1900
- if allowed_mentions is not None :
1901
- if self ._state .allowed_mentions is not None :
1902
- allowed_mentions = self ._state .allowed_mentions .merge (allowed_mentions ).to_dict ()
1903
- else :
1904
- allowed_mentions = allowed_mentions .to_dict ()
1905
- fields ["allowed_mentions" ] = allowed_mentions
1901
+ fields ["allowed_mentions" ] = self ._state .allowed_mentions .to_dict () if self ._state .allowed_mentions else None
1902
+
1903
+ view = fields .pop ("view" , None )
1904
+ self ._state .prevent_view_updates_for (self .id )
1905
+ fields ["components" ] = view .to_components () if view else []
1906
1906
1907
- try :
1908
- view = fields .pop ("view" )
1909
- except KeyError :
1910
- # To check for the view afterwards
1911
- view = None
1912
- else :
1913
- self ._state .prevent_view_updates_for (self .id )
1914
- fields ["components" ] = view .to_components () if view else []
1915
1907
if fields :
1916
1908
data = await self ._state .http .edit_message (self .channel .id , self .id , ** fields )
1917
1909
0 commit comments