aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2016-11-16 20:16:36 -0500
committerRapptz <[email protected]>2017-01-03 09:51:58 -0500
commitc205eb352827f6197daefb0457ab49e5ea88bf84 (patch)
tree93af4020aa459433444d2d883bc25d4284493438
parentMake Message.embeds to be based on discord.Embed (diff)
downloaddiscord.py-c205eb352827f6197daefb0457ab49e5ea88bf84.tar.xz
discord.py-c205eb352827f6197daefb0457ab49e5ea88bf84.zip
Re-add support for embeds.
-rw-r--r--discord/abc.py16
-rw-r--r--discord/message.py8
2 files changed, 19 insertions, 5 deletions
diff --git a/discord/abc.py b/discord/abc.py
index 306f0157..4450693c 100644
--- a/discord/abc.py
+++ b/discord/abc.py
@@ -140,12 +140,17 @@ class MessageChannel(metaclass=abc.ABCMeta):
raise NotImplementedError
@asyncio.coroutine
- def send_message(self, content, *, tts=False):
+ def send_message(self, content=None, *, tts=False, embed=None):
"""|coro|
Sends a message to the channel with the content given.
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
------------
@@ -153,6 +158,8 @@ class MessageChannel(metaclass=abc.ABCMeta):
The content of the message to send.
tts: bool
Indicates if the message should be sent using text-to-speech.
+ embed: :class:`Embed`
+ The rich embed for the content.
Raises
--------
@@ -168,8 +175,11 @@ class MessageChannel(metaclass=abc.ABCMeta):
"""
channel_id, guild_id = self._get_destination()
- content = str(content)
- data = yield from self._state.http.send_message(channel_id, content, guild_id=guild_id, tts=tts)
+ content = str(content) if content else None
+ if embed is not None:
+ embed = embed.to_dict()
+
+ data = yield from self._state.http.send_message(channel_id, content, guild_id=guild_id, tts=tts, embed=embed)
return Message(channel=self, state=self._state, data=data)
@asyncio.coroutine
diff --git a/discord/message.py b/discord/message.py
index fc462e5c..7c41efa3 100644
--- a/discord/message.py
+++ b/discord/message.py
@@ -404,7 +404,7 @@ class Message:
yield from self._state.http.delete_message(self.channel.id, self.id, getattr(self.guild, 'id', None))
@asyncio.coroutine
- def edit(self, *, content: str):
+ def edit(self, *, content: str = None, embed: Embed = None):
"""|coro|
Edits the message.
@@ -415,6 +415,8 @@ class Message:
-----------
content: str
The new content to replace the message with.
+ embed: :class:`Embed`
+ The new embed to replace the original with.
Raises
-------
@@ -423,7 +425,9 @@ class Message:
"""
guild_id = getattr(self.guild, 'id', None)
- data = yield from self._state.http.edit_message(self.id, self.channel.id, str(content), guild_id=guild_id)
+ content = str(content) if content else None
+ embed = embed.to_dict() if embed else None
+ data = yield from self._state.http.edit_message(self.id, self.channel.id, content, guild_id=guild_id, embed=embed)
self._update(channel=self.channel, data=data)
@asyncio.coroutine