Add support for rich embeds.
This commit is contained in:
@@ -1043,7 +1043,7 @@ class Client:
|
||||
return [User(**user) for user in data]
|
||||
|
||||
@asyncio.coroutine
|
||||
def send_message(self, destination, content, *, tts=False):
|
||||
def send_message(self, destination, content=None, *, tts=False, embed=None):
|
||||
"""|coro|
|
||||
|
||||
Sends a message to the destination given with the content given.
|
||||
@@ -1062,15 +1062,23 @@ class Client:
|
||||
``str`` being allowed was removed and replaced with :class:`Object`.
|
||||
|
||||
The content must be a type that can convert to a string through ``str(content)``.
|
||||
If the content is set to ``None`` (the default), then the ``embed`` parameter must
|
||||
be provided.
|
||||
|
||||
If the ``embed`` parameter is provided, it must be of type :class:`Embed` and
|
||||
it must be a rich embed type.
|
||||
|
||||
Parameters
|
||||
------------
|
||||
destination
|
||||
The location to send the message.
|
||||
content
|
||||
The content of the message to send.
|
||||
The content of the message to send. If this is missing,
|
||||
then the ``embed`` parameter must be present.
|
||||
tts : bool
|
||||
Indicates if the message should be sent using text-to-speech.
|
||||
embed: :class:`Embed`
|
||||
The rich embed for the content.
|
||||
|
||||
Raises
|
||||
--------
|
||||
@@ -1083,6 +1091,25 @@ class Client:
|
||||
InvalidArgument
|
||||
The destination parameter is invalid.
|
||||
|
||||
Examples
|
||||
----------
|
||||
|
||||
Sending a regular message:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
await client.send_message(message.channel, 'Hello')
|
||||
|
||||
Sending a TTS message:
|
||||
|
||||
await client.send_message(message.channel, 'Goodbye.', tts=True)
|
||||
|
||||
Sending an embed message:
|
||||
|
||||
em = discord.Embed(title='My Embed Title', description='My Embed Content.', colour=0xDEADBF)
|
||||
em.set_author(name='Someone', icon_url=client.user.default_avatar_url)
|
||||
await client.send_message(message.channel, embed=em)
|
||||
|
||||
Returns
|
||||
---------
|
||||
:class:`Message`
|
||||
@@ -1091,9 +1118,12 @@ class Client:
|
||||
|
||||
channel_id, guild_id = yield from self._resolve_destination(destination)
|
||||
|
||||
content = str(content)
|
||||
content = str(content) if content else None
|
||||
|
||||
data = yield from self.http.send_message(channel_id, content, guild_id=guild_id, tts=tts)
|
||||
if embed is not None:
|
||||
embed = embed.to_dict()
|
||||
|
||||
data = yield from self.http.send_message(channel_id, content, guild_id=guild_id, tts=tts, embed=embed)
|
||||
channel = self.get_channel(data.get('channel_id'))
|
||||
message = self.connection._create_message(channel=channel, **data)
|
||||
return message
|
||||
|
||||
Reference in New Issue
Block a user