diff options
| author | Red_M <[email protected]> | 2015-11-20 15:10:05 +1000 |
|---|---|---|
| committer | Red_M <[email protected]> | 2015-11-20 15:10:05 +1000 |
| commit | 36b145aee2e4e62958ecfcbad12d35a029b13754 (patch) | |
| tree | 8536a38240c9526b3f24270f6aca202a48e998da | |
| parent | Add send_typing command to allow sending typing updates. (diff) | |
| download | discord.py-36b145aee2e4e62958ecfcbad12d35a029b13754.tar.xz discord.py-36b145aee2e4e62958ecfcbad12d35a029b13754.zip | |
Allow sending raw file objects in memory with client.send_raw_file
| -rw-r--r-- | discord/client.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/discord/client.py b/discord/client.py index 8a6d10dd..12bc6766 100644 --- a/discord/client.py +++ b/discord/client.py @@ -705,6 +705,38 @@ class Client(object): message = Message(channel=channel, **data) return message + def send_raw_file(self, destination, filename, file): + """Sends a message to the destination given with the file object given. + + The destination parameter follows the same rules as :meth:`send_message`. + + Note that this requires proper permissions in order to work. + This function raises :exc:`HTTPException` if the request failed. + + :param destination: The location to send the message. + :param filename: The name of the file to send. + :param file: The file object to send. + :return: The :class:`Message` sent. + """ + + channel_id = self._resolve_destination(destination) + + url = '{base}/{id}/messages'.format(base=endpoints.CHANNELS, id=channel_id) + response = None + + files = { + 'file': (filename, file) + } + response = requests.post(url, files=files, headers=self.headers) + + log.debug(request_logging_format.format(response=response)) + _verify_successful_response(response) + data = response.json() + log.debug(request_success_log.format(response=response, json=response.text, data=filename)) + channel = self.get_channel(data.get('channel_id')) + message = Message(channel=channel, **data) + return message + def delete_message(self, message): """Deletes a :class:`Message`. |