aboutsummaryrefslogtreecommitdiff
path: root/discord/client.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2016-11-13 05:05:22 -0500
committerRapptz <[email protected]>2016-11-13 05:07:58 -0500
commitaf46718460d42cabe9c557719ef72e0df0742b54 (patch)
tree68764a275aae61e08d16ebe5a447d82a539dea26 /discord/client.py
parentVersion bump to v0.14.3 (diff)
downloaddiscord.py-af46718460d42cabe9c557719ef72e0df0742b54.tar.xz
discord.py-af46718460d42cabe9c557719ef72e0df0742b54.zip
Add support for rich embeds.
Diffstat (limited to 'discord/client.py')
-rw-r--r--discord/client.py38
1 files changed, 34 insertions, 4 deletions
diff --git a/discord/client.py b/discord/client.py
index f9888fe7..f7d223bb 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -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
+
+ 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)
+ 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