From f71fd33eba797dbb84ee8271bdca47edf6c0e1d2 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Mon, 15 Apr 2019 07:15:28 -0400 Subject: [PATCH] Fix UnboundLocalError when RequestsWebhookAdapter raises an error. --- discord/webhook.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/discord/webhook.py b/discord/webhook.py index d44a5e94f..6343b852f 100644 --- a/discord/webhook.py +++ b/discord/webhook.py @@ -137,14 +137,17 @@ class WebhookAdapter: files_to_pass = None url = '%s?wait=%d' % (self._request_url, wait) + maybe_coro = None try: maybe_coro = self.request('POST', url, multipart=multipart, payload=data, files=files_to_pass) finally: - if cleanup is not None: + if maybe_coro is not None and cleanup is not None: if not asyncio.iscoroutine(maybe_coro): cleanup() else: maybe_coro = self._wrap_coroutine_and_cleanup(maybe_coro, cleanup) + + # if request raises up there then this should never be `None` return self.handle_execution_response(maybe_coro, wait=wait) class AsyncWebhookAdapter(WebhookAdapter):