From 718a4658ebd45bc77286ae81feefdeeceedffed6 Mon Sep 17 00:00:00 2001
From: DjDeveloperr <djsandhu2005@gmail.com>
Date: Thu, 29 Apr 2021 14:45:05 +0530
Subject: [PATCH] fix raw response compat

---
 src/rest/bucket.ts | 18 ++++++++++++------
 test/index.ts      |  2 ++
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/rest/bucket.ts b/src/rest/bucket.ts
index e8ec3a9..da9d3a3 100644
--- a/src/rest/bucket.ts
+++ b/src/rest/bucket.ts
@@ -10,11 +10,17 @@ import { RequestQueue } from './queue.ts'
 import { APIRequest } from './request.ts'
 
 function parseResponse(res: Response, raw: boolean): any {
-  if (raw) return res
-  if (res.status === 204) return undefined
-  if (res.headers.get('content-type')?.startsWith('application/json') === true)
-    return res.json()
-  return res.arrayBuffer().then((e) => new Uint8Array(e))
+  let result
+  if (res.status === 204) result = Promise.resolve(undefined)
+  else if (
+    res.headers.get('content-type')?.startsWith('application/json') === true
+  )
+    result = res.json()
+  else result = res.arrayBuffer().then((e) => new Uint8Array(e))
+
+  if (raw) {
+    return { response: res, body: result }
+  } else return result
 }
 
 function getAPIOffset(serverDate: number | string): number {
@@ -197,7 +203,7 @@ export class BucketHandler {
 
       let data
       try {
-        data = await parseResponse(res, request.options.rawResponse ?? false)
+        data = await parseResponse(res, false)
       } catch (err) {
         throw new HTTPError(
           err.message,
diff --git a/test/index.ts b/test/index.ts
index 872f457..9e17c19 100644
--- a/test/index.ts
+++ b/test/index.ts
@@ -254,6 +254,8 @@ client.on('messageCreate', async (msg: Message) => {
       buf += `\n${role.name === '@everyone' ? 'everyone' : role.name}`
     }
     msg.reply(buf)
+  } else if (msg.content === '!addrole') {
+    msg.member?.roles.add('837255383759716362')
   } else if (msg.content === '!timer') {
     msg.channel.send('3...').then((msg) => {
       setTimeout(() => {