From bf2066278e872a86da64ef4d4ce95dfaf8baf4e7 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sat, 8 Apr 2017 03:17:30 -0400 Subject: Add support for multiple file attachments. This is a breaking change. No longer does Messageable.send have a filename keyword argument, instead this is all handled through the discord.File model. To upload many files you must specify a list of discord.File objects. --- discord/http.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'discord/http.py') diff --git a/discord/http.py b/discord/http.py index 9f43faad..e5d0c094 100644 --- a/discord/http.py +++ b/discord/http.py @@ -306,7 +306,7 @@ class HTTPClient: def send_typing(self, channel_id): return self.request(Route('POST', '/channels/{channel_id}/typing', channel_id=channel_id)) - def send_file(self, channel_id, buffer, *, filename=None, content=None, tts=False, embed=None): + def send_files(self, channel_id, *, files, content=None, tts=False, embed=None): r = Route('POST', '/channels/{channel_id}/messages', channel_id=channel_id) form = aiohttp.FormData() @@ -317,7 +317,12 @@ class HTTPClient: payload['embed'] = embed form.add_field('payload_json', utils.to_json(payload)) - form.add_field('file', buffer, filename=filename, content_type='application/octet-stream') + if len(files) == 1: + fp = files[0] + form.add_field('file', fp[0], filename=fp[1], content_type='application/octet-stream') + else: + for index, (buffer, filename) in enumerate(files): + form.add_field('file%s' % index, buffer, filename=filename, content_type='application/octet-stream') return self.request(r, data=form) -- cgit v1.2.3