diff options
| author | Rapptz <[email protected]> | 2016-06-18 02:09:50 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2016-06-18 02:14:44 -0400 |
| commit | b3edb31df5500e8e850450577e9541af07a9508b (patch) | |
| tree | b171f6c152a889d26395dc46ea66176780d4556c /discord/client.py | |
| parent | Fix HTTPClient.recreate to actually work. (diff) | |
| download | discord.py-b3edb31df5500e8e850450577e9541af07a9508b.tar.xz discord.py-b3edb31df5500e8e850450577e9541af07a9508b.zip | |
Add support for message pinning.
This includes `Client.pin_message`, `Client.unpin_message` and
`Client.pins_from`. This also adds the `Message.pinned` attribute
to the `Message` object.
Diffstat (limited to 'discord/client.py')
| -rw-r--r-- | discord/client.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/discord/client.py b/discord/client.py index d786cca4..039188ef 100644 --- a/discord/client.py +++ b/discord/client.py @@ -1110,6 +1110,75 @@ class Client: data = yield from self.http.get_message(channel.id, id) return Message(channel=channel, **data) + @asyncio.coroutine + def pin_message(self, message): + """|coro| + + Pins a message. You must have Manage Messages permissions + to do this in a non-private channel context. + + Parameters + ----------- + message: :class:`Message` + The message to pin. + + Raises + ------- + Forbidden + You do not have permissions to pin the message. + NotFound + The message or channel was not found. + HTTPException + Pinning the message failed, probably due to the channel + having more than 50 pinned messages. + """ + yield from self.http.pin_message(message.channel.id, message.id) + + @asyncio.coroutine + def unpin_message(self, message): + """|coro| + + Unpins a message. You must have Manage Messages permissions + to do this in a non-private channel context. + + Parameters + ----------- + message: :class:`Message` + The message to unpin. + + Raises + ------- + Forbidden + You do not have permissions to unpin the message. + NotFound + The message or channel was not found. + HTTPException + Unpinning the message failed. + """ + yield from self.http.unpin_message(message.channel.id, message.id) + + @asyncio.coroutine + def pins_from(self, channel): + """|coro| + + Returns a list of :class:`Message` that are currently pinned for + the specified :class:`Channel` or :class:`PrivateChannel`. + + Parameters + ----------- + channel: :class:`Channel` or :class:`PrivateChannel` + The channel to look through pins for. + + Raises + ------- + NotFound + The channel was not found. + HTTPException + Retrieving the pinned messages failed. + """ + + data = yield from self.http.pins_from(channel.id) + return [Message(channel=channel, **m) for m in data] def _logs_from(self, channel, limit=100, before=None, after=None): """|coro| |