aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2015-08-21 23:40:20 -0400
committerRapptz <[email protected]>2015-08-21 23:40:20 -0400
commitb6e680eddef66f97238f908c7f6437652e814ba5 (patch)
treee1f2eaa1b862f012090f8fce3d5d33a0dbf21f35
parentChange the way timestamps are parsed. (diff)
downloaddiscord.py-b6e680eddef66f97238f908c7f6437652e814ba5.tar.xz
discord.py-b6e680eddef66f97238f908c7f6437652e814ba5.zip
Add logs_from function to get channel logs from a channel.
-rw-r--r--discord/client.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/discord/client.py b/discord/client.py
index f81db1c1..b020f90a 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -357,6 +357,32 @@ class Client(object):
self.ws.send(json.dumps(second_payload))
self._is_logged_in = True
+ def logs_from(self, channel, limit=500):
+ """A generator that obtains logs from a specified channel.
+
+ Yielding from the generator returns a :class:`Message` object with the message data.
+
+ Example: ::
+
+ for message in client.logs_from(channel):
+ if message.content.startswith('!hello'):
+ client.edit_message(message, 'goodbye')
+
+
+ :param channel: The :class:`Channel` to obtain the logs from.
+ :param limit: The number of messages to retrieve.
+ """
+
+ url = '{}/{}/messages'.format(endpoints.CHANNELS, channel.id)
+ params = {
+ 'limit': limit
+ }
+ response = requests.get(url, params=params, headers=self.headers)
+ if response.status_code == 200:
+ messages = response.json()
+ for message in messages:
+ yield Message(channel=channel, **message)
+
def event(self, function):
"""A decorator that registers an event to listen to.