Browse Source

Re-add support for embeds.

pull/447/head
Rapptz 9 years ago
parent
commit
c205eb3528
  1. 16
      discord/abc.py
  2. 8
      discord/message.py

16
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

8
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

Loading…
Cancel
Save