Add support for sending multiple embeds
This commit is contained in:
parent
8b7e5a50b4
commit
47e6a754e4
@ -1158,7 +1158,7 @@ class Messageable(Protocol):
|
|||||||
content: Optional[str] = ...,
|
content: Optional[str] = ...,
|
||||||
*,
|
*,
|
||||||
tts: bool = ...,
|
tts: bool = ...,
|
||||||
embed: Embed = ...,
|
embeds: List[Embed] = ...,
|
||||||
files: List[File] = ...,
|
files: List[File] = ...,
|
||||||
delete_after: int = ...,
|
delete_after: int = ...,
|
||||||
nonce: Union[str, int] = ...,
|
nonce: Union[str, int] = ...,
|
||||||
@ -1169,9 +1169,9 @@ class Messageable(Protocol):
|
|||||||
) -> Message:
|
) -> Message:
|
||||||
...
|
...
|
||||||
|
|
||||||
async def send(self, content=None, *, tts=False, embed=None, file=None,
|
async def send(self, content=None, *, tts=False, embed=None, embeds=None,
|
||||||
files=None, delete_after=None, nonce=None,
|
file=None, files=None, delete_after=None,
|
||||||
allowed_mentions=None, reference=None,
|
nonce=None, allowed_mentions=None, reference=None,
|
||||||
mention_author=None, view=None):
|
mention_author=None, view=None):
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
||||||
@ -1185,9 +1185,11 @@ class Messageable(Protocol):
|
|||||||
single :class:`~discord.File` object. To upload multiple files, the ``files``
|
single :class:`~discord.File` object. To upload multiple files, the ``files``
|
||||||
parameter should be used with a :class:`list` of :class:`~discord.File` objects.
|
parameter should be used with a :class:`list` of :class:`~discord.File` objects.
|
||||||
**Specifying both parameters will lead to an exception**.
|
**Specifying both parameters will lead to an exception**.
|
||||||
|
|
||||||
If the ``embed`` parameter is provided, it must be of type :class:`~discord.Embed` and
|
To upload a single embed, the ``embed`` parameter should be used with a
|
||||||
it must be a rich embed type.
|
single :class:`~discord.Embed` object. To upload multiple embeds, the ``embeds``
|
||||||
|
parameter should be used with a :class:`list` of :class:`~discord.Embed` objects.
|
||||||
|
**Specifying both parameters will lead to an exception**.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
------------
|
------------
|
||||||
@ -1232,6 +1234,8 @@ class Messageable(Protocol):
|
|||||||
.. versionadded:: 1.6
|
.. versionadded:: 1.6
|
||||||
view: :class:`discord.ui.View`
|
view: :class:`discord.ui.View`
|
||||||
A Discord UI View to add to the message.
|
A Discord UI View to add to the message.
|
||||||
|
embeds: List[:class:`~discord.Embed`]
|
||||||
|
A list of embeds to upload. Must be a maximum of 10.
|
||||||
|
|
||||||
.. versionadded:: 2.0
|
.. versionadded:: 2.0
|
||||||
|
|
||||||
@ -1244,6 +1248,7 @@ class Messageable(Protocol):
|
|||||||
~discord.InvalidArgument
|
~discord.InvalidArgument
|
||||||
The ``files`` list is not of the appropriate size,
|
The ``files`` list is not of the appropriate size,
|
||||||
you specified both ``file`` and ``files``,
|
you specified both ``file`` and ``files``,
|
||||||
|
or you specified both ``embed`` and ``embeds``,
|
||||||
or the ``reference`` object is not a :class:`~discord.Message`
|
or the ``reference`` object is not a :class:`~discord.Message`
|
||||||
or :class:`~discord.MessageReference`.
|
or :class:`~discord.MessageReference`.
|
||||||
|
|
||||||
@ -1256,8 +1261,17 @@ class Messageable(Protocol):
|
|||||||
channel = await self._get_channel()
|
channel = await self._get_channel()
|
||||||
state = self._state
|
state = self._state
|
||||||
content = str(content) if content is not None else None
|
content = str(content) if content is not None else None
|
||||||
|
|
||||||
|
if embed is not None and embeds is not None:
|
||||||
|
raise InvalidArgument('cannot pass both embed and embeds parameter to send()')
|
||||||
|
|
||||||
if embed is not None:
|
if embed is not None:
|
||||||
embed = embed.to_dict()
|
embed = embed.to_dict()
|
||||||
|
|
||||||
|
elif embeds is not None:
|
||||||
|
if len(embeds) > 10:
|
||||||
|
raise InvalidArgument('embeds parameter must be a list of up to 10 elements')
|
||||||
|
embeds = [embed.to_dict() for embed in embeds]
|
||||||
|
|
||||||
if allowed_mentions is not None:
|
if allowed_mentions is not None:
|
||||||
if state.allowed_mentions is not None:
|
if state.allowed_mentions is not None:
|
||||||
@ -1294,8 +1308,8 @@ class Messageable(Protocol):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
data = await state.http.send_files(channel.id, files=[file], allowed_mentions=allowed_mentions,
|
data = await state.http.send_files(channel.id, files=[file], allowed_mentions=allowed_mentions,
|
||||||
content=content, tts=tts, embed=embed, nonce=nonce,
|
content=content, tts=tts, embed=embed, embeds=embeds,
|
||||||
message_reference=reference, components=components)
|
nonce=nonce, message_reference=reference, components=components)
|
||||||
finally:
|
finally:
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
@ -1307,14 +1321,15 @@ class Messageable(Protocol):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
data = await state.http.send_files(channel.id, files=files, content=content, tts=tts,
|
data = await state.http.send_files(channel.id, files=files, content=content, tts=tts,
|
||||||
embed=embed, nonce=nonce, allowed_mentions=allowed_mentions,
|
embed=embed, embeds=embeds, nonce=nonce,
|
||||||
message_reference=reference, components=components)
|
allowed_mentions=allowed_mentions, message_reference=reference,
|
||||||
|
components=components)
|
||||||
finally:
|
finally:
|
||||||
for f in files:
|
for f in files:
|
||||||
f.close()
|
f.close()
|
||||||
else:
|
else:
|
||||||
data = await state.http.send_message(channel.id, content, tts=tts, embed=embed,
|
data = await state.http.send_message(channel.id, content, tts=tts, embed=embed,
|
||||||
nonce=nonce, allowed_mentions=allowed_mentions,
|
embeds=embeds, nonce=nonce, allowed_mentions=allowed_mentions,
|
||||||
message_reference=reference, components=components)
|
message_reference=reference, components=components)
|
||||||
|
|
||||||
ret = state.create_message(channel=channel, data=data)
|
ret = state.create_message(channel=channel, data=data)
|
||||||
|
@ -412,6 +412,7 @@ class HTTPClient:
|
|||||||
*,
|
*,
|
||||||
tts: bool = False,
|
tts: bool = False,
|
||||||
embed: Optional[embed.Embed] = None,
|
embed: Optional[embed.Embed] = None,
|
||||||
|
embeds: Optional[List[embed.Embed]] = None,
|
||||||
nonce: Optional[str] = None,
|
nonce: Optional[str] = None,
|
||||||
allowed_mentions: bool = None,
|
allowed_mentions: bool = None,
|
||||||
message_reference: bool = None,
|
message_reference: bool = None,
|
||||||
@ -427,7 +428,10 @@ class HTTPClient:
|
|||||||
payload['tts'] = True
|
payload['tts'] = True
|
||||||
|
|
||||||
if embed:
|
if embed:
|
||||||
payload['embed'] = embed
|
payload['embeds'] = [embed]
|
||||||
|
|
||||||
|
if embeds:
|
||||||
|
payload['embeds'] = embeds
|
||||||
|
|
||||||
if nonce:
|
if nonce:
|
||||||
payload['nonce'] = nonce
|
payload['nonce'] = nonce
|
||||||
@ -466,7 +470,7 @@ class HTTPClient:
|
|||||||
if content:
|
if content:
|
||||||
payload['content'] = content
|
payload['content'] = content
|
||||||
if embed:
|
if embed:
|
||||||
payload['embed'] = embed
|
payload['embeds'] = [embed]
|
||||||
if embeds:
|
if embeds:
|
||||||
payload['embeds'] = embeds
|
payload['embeds'] = embeds
|
||||||
if nonce:
|
if nonce:
|
||||||
@ -510,6 +514,7 @@ class HTTPClient:
|
|||||||
content: Optional[str] = None,
|
content: Optional[str] = None,
|
||||||
tts: bool = False,
|
tts: bool = False,
|
||||||
embed: Optional[embed.Embed] = None,
|
embed: Optional[embed.Embed] = None,
|
||||||
|
embeds: Optional[List[embed.Embed]] = None,
|
||||||
nonce: Optional[str] = None,
|
nonce: Optional[str] = None,
|
||||||
allowed_mentions: Optional[message.AllowedMentions] = None,
|
allowed_mentions: Optional[message.AllowedMentions] = None,
|
||||||
message_reference: Optional[message.MessageReference] = None,
|
message_reference: Optional[message.MessageReference] = None,
|
||||||
@ -522,6 +527,7 @@ class HTTPClient:
|
|||||||
content=content,
|
content=content,
|
||||||
tts=tts,
|
tts=tts,
|
||||||
embed=embed,
|
embed=embed,
|
||||||
|
embeds=embeds,
|
||||||
nonce=nonce,
|
nonce=nonce,
|
||||||
allowed_mentions=allowed_mentions,
|
allowed_mentions=allowed_mentions,
|
||||||
message_reference=message_reference,
|
message_reference=message_reference,
|
||||||
|
@ -1110,7 +1110,17 @@ class Message(Hashable):
|
|||||||
...
|
...
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
async def edit(self) -> None:
|
async def edit(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
content: Optional[str] = ...,
|
||||||
|
embeds: Optional[List[Embed]] = ...,
|
||||||
|
attachments: List[Attachment] = ...,
|
||||||
|
suppress: bool = ...,
|
||||||
|
delete_after: Optional[float] = ...,
|
||||||
|
allowed_mentions: Optional[AllowedMentions] = ...,
|
||||||
|
view: Optional[View] = ...,
|
||||||
|
) -> None:
|
||||||
...
|
...
|
||||||
|
|
||||||
async def edit(self, **fields) -> None:
|
async def edit(self, **fields) -> None:
|
||||||
@ -1155,6 +1165,10 @@ class Message(Hashable):
|
|||||||
view: Optional[:class:`~discord.ui.View`]
|
view: Optional[:class:`~discord.ui.View`]
|
||||||
The updated view to update this message with. If ``None`` is passed then
|
The updated view to update this message with. If ``None`` is passed then
|
||||||
the view is removed.
|
the view is removed.
|
||||||
|
embeds: Optional[List[:class:`Embeds`]]
|
||||||
|
The new embeds to replace the original with.
|
||||||
|
Could be ``None`` to remove the embeds.
|
||||||
|
Must be a maximum of 10.
|
||||||
|
|
||||||
.. versionadded:: 2.0
|
.. versionadded:: 2.0
|
||||||
|
|
||||||
@ -1165,6 +1179,8 @@ class Message(Hashable):
|
|||||||
Forbidden
|
Forbidden
|
||||||
Tried to suppress a message without permissions or
|
Tried to suppress a message without permissions or
|
||||||
edited a message's content or embed that isn't yours.
|
edited a message's content or embed that isn't yours.
|
||||||
|
~discord.InvalidArgument
|
||||||
|
You specified both ``embed`` and ``embeds``
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -1176,12 +1192,24 @@ class Message(Hashable):
|
|||||||
fields['content'] = str(content)
|
fields['content'] = str(content)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
embed = fields['embed']
|
fields['embed']
|
||||||
|
fields['embeds']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if embed is not None:
|
raise InvalidArgument('cannot pass both embed and embeds parameter to edit()')
|
||||||
fields['embed'] = embed.to_dict()
|
try:
|
||||||
|
embeds = fields.pop('embeds')
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
fields['embeds'] = [embed.to_dict() for embed in embeds]
|
||||||
|
try:
|
||||||
|
embed = fields.pop('embed')
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
fields['embeds'] = [embed.to_dict()]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
suppress = fields.pop('suppress')
|
suppress = fields.pop('suppress')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user