From fcc540ec44717c700d8acf7bc5e99f934e08bb15 Mon Sep 17 00:00:00 2001 From: Khazhismel Date: Mon, 16 Nov 2015 18:17:38 -0500 Subject: [PATCH] Add before and after params to logs_from. --- discord/client.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/discord/client.py b/discord/client.py index 1f7b68743..462161916 100644 --- a/discord/client.py +++ b/discord/client.py @@ -816,11 +816,13 @@ class Client(object): self._is_logged_in = False log.debug(request_logging_format.format(response=response)) - def logs_from(self, channel, limit=100): + def logs_from(self, channel, limit=100, before=None, after=None): """A generator that obtains logs from a specified channel. Yielding from the generator returns a :class:`Message` object with the message data. + Will return the newest messages within the specified range, up to `limit` messages. + This function raises :exc:`HTTPException` if the request failed. Example: :: @@ -833,12 +835,19 @@ class Client(object): :param channel: The :class:`Channel` to obtain the logs from. :param limit: The number of messages to retrieve. + :param before: Message before which all returned messages must be. + :param after: Message after which all returned messages must be. """ url = '{}/{}/messages'.format(endpoints.CHANNELS, channel.id) params = { 'limit': limit } + if before: + params['before'] = before.id + if after: + params['after'] = after.id + response = requests.get(url, params=params, headers=self.headers) log.debug(request_logging_format.format(response=response)) _verify_successful_response(response)