@discordeno/rest 19.0.0-next.dea9d1d → 19.0.0-next.dfb7f93

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/manager.js CHANGED
@@ -1,510 +1,41 @@
1
1
  /* eslint-disable @typescript-eslint/restrict-template-expressions */ /* eslint-disable no-const-assign */ import { InteractionResponseTypes } from '@discordeno/types';
2
- import { calculateBits, camelize, camelToSnakeCase, delay, encode, getBotIdFromToken, isGetMessagesAfter, isGetMessagesAround, isGetMessagesBefore, isGetMessagesLimit, logger, processReactionString, urlToBase64 } from '@discordeno/utils';
2
+ import { calculateBits, camelize, camelToSnakeCase, delay, getBotIdFromToken, logger, processReactionString, urlToBase64 } from '@discordeno/utils';
3
3
  import fetch from 'node-fetch';
4
4
  import { createInvalidRequestBucket } from './invalidBucket.js';
5
5
  import { Queue } from './queue.js';
6
+ import { createRoutes } from './routes.js';
6
7
  // TODO: make dynamic based on package.json file
7
8
  const version = '19.0.0-alpha.1';
9
+ export const DISCORD_API_VERSION = 10;
10
+ export const DISCORD_API_URL = 'https://discord.com/api';
11
+ export const AUDIT_LOG_REASON_HEADER = 'x-audit-log-reason';
12
+ export const RATE_LIMIT_REMAINING_HEADER = 'x-ratelimit-remaining';
13
+ export const RATE_LIMIT_RESET_AFTER_HEADER = 'x-ratelimit-reset-after';
14
+ export const RATE_LIMIT_GLOBAL_HEADER = 'x-ratelimit-global';
15
+ export const RATE_LIMIT_BUCKET_HEADER = 'x-ratelimit-bucket';
16
+ export const RATE_LIMIT_LIMIT_HEADER = 'x-ratelimit-limit';
17
+ export const RATE_LIMIT_SCOPE_HEADER = 'x-ratelimit-scope';
8
18
  export function createRestManager(options) {
9
- // Falsy token string check
10
- if (!options.token) throw new Error('You must provide a valid token.');
19
+ const applicationId = options.applicationId ? BigInt(options.applicationId) : options.token ? getBotIdFromToken(options.token) : undefined;
20
+ if (!applicationId) {
21
+ throw new Error('`applicationId` was not provided and was not able to extract the id from the bots token. Please explicitly pass `applicationId` to the rest manager.');
22
+ }
23
+ const baseUrl = options.proxy?.baseUrl ?? DISCORD_API_URL;
11
24
  const rest = {
12
- token: options.token,
13
- applicationId: options.applicationId ? BigInt(options.applicationId) : getBotIdFromToken(options.token),
14
- version: options.version ?? 10,
15
- baseUrl: options.proxy?.baseUrl ?? 'https://discord.com/api',
16
- maxRetryCount: Infinity,
25
+ applicationId,
26
+ authorization: options.proxy?.authorization,
27
+ baseUrl,
28
+ deleteQueueDelay: 60000,
17
29
  globallyRateLimited: false,
30
+ invalidBucket: createInvalidRequestBucket({}),
31
+ isProxied: !baseUrl.startsWith(DISCORD_API_URL),
32
+ maxRetryCount: Infinity,
18
33
  processingRateLimitedPaths: false,
19
- deleteQueueDelay: 60000,
20
34
  queues: new Map(),
21
35
  rateLimitedPaths: new Map(),
22
- invalidBucket: createInvalidRequestBucket({}),
23
- authorization: options.proxy?.authorization,
24
- routes: {
25
- webhooks: {
26
- id: (webhookId)=>{
27
- return `/webhooks/${webhookId}`;
28
- },
29
- message: (webhookId, token, messageId, options)=>{
30
- let url = `/webhooks/${webhookId}/${token}/messages/${messageId}?`;
31
- if (options) {
32
- if (options.threadId) url += `thread_id=${options.threadId}`;
33
- }
34
- return url;
35
- },
36
- original: (webhookId, token, options)=>{
37
- let url = `/webhooks/${webhookId}/${token}/messages/@original?`;
38
- if (options) {
39
- if (options.threadId) url += `thread_id=${options.threadId}`;
40
- }
41
- return url;
42
- },
43
- webhook: (webhookId, token, options)=>{
44
- let url = `/webhooks/${webhookId}/${token}?`;
45
- if (options) {
46
- if (options?.wait !== undefined) url += `wait=${options.wait.toString()}`;
47
- if (options.threadId) url += `thread_id=${options.threadId}`;
48
- }
49
- return url;
50
- }
51
- },
52
- // Miscellaneous Endpoints
53
- sessionInfo: ()=>rest.routes.gatewayBot(),
54
- // Channel Endpoints
55
- channels: {
56
- bulk: (channelId)=>{
57
- return `/channels/${channelId}/messages/bulk-delete`;
58
- },
59
- dm: ()=>{
60
- return '/users/@me/channels';
61
- },
62
- pin: (channelId, messageId)=>{
63
- return `/channels/${channelId}/pins/${messageId}`;
64
- },
65
- pins: (channelId)=>{
66
- return `/channels/${channelId}/pins`;
67
- },
68
- reactions: {
69
- bot: (channelId, messageId, emoji)=>{
70
- return `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}/@me`;
71
- },
72
- user: (channelId, messageId, emoji, userId)=>{
73
- return `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}/${userId}`;
74
- },
75
- all: (channelId, messageId)=>{
76
- return `/channels/${channelId}/messages/${messageId}/reactions`;
77
- },
78
- emoji: (channelId, messageId, emoji, options)=>{
79
- let url = `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}?`;
80
- if (options) {
81
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
82
- if (options.after) url += `after=${options.after}`;
83
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
84
- if (options.limit) url += `&limit=${options.limit}`;
85
- }
86
- return url;
87
- },
88
- message: (channelId, messageId, emoji, options)=>{
89
- let url = `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}?`;
90
- if (options) {
91
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
92
- if (options.after) url += `after=${options.after}`;
93
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
94
- if (options.limit) url += `&limit=${options.limit}`;
95
- }
96
- return url;
97
- }
98
- },
99
- webhooks: (channelId)=>{
100
- return `/channels/${channelId}/webhooks`;
101
- },
102
- channel: (channelId)=>{
103
- return `/channels/${channelId}`;
104
- },
105
- follow: (channelId)=>{
106
- return `/channels/${channelId}/followers`;
107
- },
108
- forum: (channelId)=>{
109
- return `/channels/${channelId}/threads?has_message=true`;
110
- },
111
- invites: (channelId)=>{
112
- return `/channels/${channelId}/invites`;
113
- },
114
- message: (channelId, messageId)=>{
115
- return `/channels/${channelId}/messages/${messageId}`;
116
- },
117
- messages: (channelId, options)=>{
118
- let url = `/channels/${channelId}/messages?`;
119
- if (options) {
120
- if (isGetMessagesAfter(options) && options.after) {
121
- url += `after=${options.after}`;
122
- }
123
- if (isGetMessagesBefore(options) && options.before) {
124
- url += `&before=${options.before}`;
125
- }
126
- if (isGetMessagesAround(options) && options.around) {
127
- url += `&around=${options.around}`;
128
- }
129
- if (isGetMessagesLimit(options) && options.limit) {
130
- url += `&limit=${options.limit}`;
131
- }
132
- }
133
- return url;
134
- },
135
- overwrite: (channelId, overwriteId)=>{
136
- return `/channels/${channelId}/permissions/${overwriteId}`;
137
- },
138
- crosspost: (channelId, messageId)=>{
139
- return `/channels/${channelId}/messages/${messageId}/crosspost`;
140
- },
141
- stages: ()=>{
142
- return '/stage-instances';
143
- },
144
- stage: (channelId)=>{
145
- return `/stage-instances/${channelId}`;
146
- },
147
- // Thread Endpoints
148
- threads: {
149
- message: (channelId, messageId)=>{
150
- return `/channels/${channelId}/messages/${messageId}/threads`;
151
- },
152
- all: (channelId)=>{
153
- return `/channels/${channelId}/threads`;
154
- },
155
- active: (guildId)=>{
156
- return `/guilds/${guildId}/threads/active`;
157
- },
158
- members: (channelId)=>{
159
- return `/channels/${channelId}/thread-members`;
160
- },
161
- me: (channelId)=>{
162
- return `/channels/${channelId}/thread-members/@me`;
163
- },
164
- user: (channelId, userId)=>{
165
- return `/channels/${channelId}/thread-members/${userId}`;
166
- },
167
- archived: (channelId)=>{
168
- return `/channels/${channelId}/threads/archived`;
169
- },
170
- public: (channelId, options)=>{
171
- let url = `/channels/${channelId}/threads/archived/public?`;
172
- if (options) {
173
- if (options.before) {
174
- url += `before=${new Date(options.before).toISOString()}`;
175
- }
176
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
177
- if (options.limit) url += `&limit=${options.limit}`;
178
- }
179
- return url;
180
- },
181
- private: (channelId, options)=>{
182
- let url = `/channels/${channelId}/threads/archived/private?`;
183
- if (options) {
184
- if (options.before) {
185
- url += `before=${new Date(options.before).toISOString()}`;
186
- }
187
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
188
- if (options.limit) url += `&limit=${options.limit}`;
189
- }
190
- return url;
191
- },
192
- joined: (channelId, options)=>{
193
- let url = `/channels/${channelId}/users/@me/threads/archived/private?`;
194
- if (options) {
195
- if (options.before) {
196
- url += `before=${new Date(options.before).toISOString()}`;
197
- }
198
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
199
- if (options.limit) url += `&limit=${options.limit}`;
200
- }
201
- return url;
202
- }
203
- },
204
- typing: (channelId)=>{
205
- return `/channels/${channelId}/typing`;
206
- }
207
- },
208
- // Guild Endpoints
209
- guilds: {
210
- all: ()=>{
211
- return '/guilds';
212
- },
213
- auditlogs: (guildId, options)=>{
214
- let url = `/guilds/${guildId}/audit-logs?`;
215
- if (options) {
216
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
217
- if (options.actionType) url += `action_type=${options.actionType}`;
218
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
219
- if (options.before) url += `&before=${options.before}`;
220
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
221
- if (options.after) url += `&after=${options.after}`;
222
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
223
- if (options.limit) url += `&limit=${options.limit}`;
224
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
225
- if (options.userId) url += `&user_id=${options.userId}`;
226
- }
227
- return url;
228
- },
229
- automod: {
230
- rule: (guildId, ruleId)=>{
231
- return `/guilds/${guildId}/auto-moderation/rules/${ruleId}`;
232
- },
233
- rules: (guildId)=>{
234
- return `/guilds/${guildId}/auto-moderation/rules`;
235
- }
236
- },
237
- channels: (guildId)=>{
238
- return `/guilds/${guildId}/channels`;
239
- },
240
- emoji: (guildId, emojiId)=>{
241
- return `/guilds/${guildId}/emojis/${emojiId}`;
242
- },
243
- emojis: (guildId)=>{
244
- return `/guilds/${guildId}/emojis`;
245
- },
246
- events: {
247
- events: (guildId, withUserCount)=>{
248
- let url = `/guilds/${guildId}/scheduled-events?`;
249
- if (withUserCount !== undefined) {
250
- url += `with_user_count=${withUserCount.toString()}`;
251
- }
252
- return url;
253
- },
254
- event: (guildId, eventId, withUserCount)=>{
255
- let url = `/guilds/${guildId}/scheduled-events/${eventId}`;
256
- if (withUserCount !== undefined) {
257
- url += `with_user_count=${withUserCount.toString()}`;
258
- }
259
- return url;
260
- },
261
- users: (guildId, eventId, options)=>{
262
- let url = `/guilds/${guildId}/scheduled-events/${eventId}/users?`;
263
- if (options) {
264
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
265
- if (options.limit !== undefined) url += `limit=${options.limit}`;
266
- if (options.withMember !== undefined) {
267
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
268
- url += `&with_member=${options.withMember.toString()}`;
269
- }
270
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
271
- if (options.after !== undefined) url += `&after=${options.after}`;
272
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
273
- if (options.before !== undefined) url += `&before=${options.before}`;
274
- }
275
- return url;
276
- }
277
- },
278
- guild (guildId, withCounts) {
279
- let url = `/guilds/${guildId}?`;
280
- if (withCounts !== undefined) {
281
- url += `with_counts=${withCounts.toString()}`;
282
- }
283
- return url;
284
- },
285
- integration (guildId, integrationId) {
286
- return `/guilds/${guildId}/integrations/${integrationId}`;
287
- },
288
- integrations: (guildId)=>{
289
- return `/guilds/${guildId}/integrations?include_applications=true`;
290
- },
291
- invite (inviteCode, options) {
292
- let url = `/invites/${inviteCode}?`;
293
- if (options) {
294
- if (options.withCounts !== undefined) {
295
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
296
- url += `with_counts=${options.withCounts.toString()}`;
297
- }
298
- if (options.withExpiration !== undefined) {
299
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
300
- url += `&with_expiration=${options.withExpiration.toString()}`;
301
- }
302
- if (options.scheduledEventId) {
303
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
304
- url += `&guild_scheduled_event_id=${options.scheduledEventId}`;
305
- }
306
- }
307
- return url;
308
- },
309
- invites: (guildId)=>{
310
- return `/guilds/${guildId}/invites`;
311
- },
312
- leave: (guildId)=>{
313
- return `/users/@me/guilds/${guildId}`;
314
- },
315
- members: {
316
- ban: (guildId, userId)=>{
317
- return `/guilds/${guildId}/bans/${userId}`;
318
- },
319
- bans: (guildId, options)=>{
320
- let url = `/guilds/${guildId}/bans?`;
321
- if (options) {
322
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
323
- if (options.limit) url += `limit=${options.limit}`;
324
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
325
- if (options.after) url += `&after=${options.after}`;
326
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
327
- if (options.before) url += `&before=${options.before}`;
328
- }
329
- return url;
330
- },
331
- bot: (guildId)=>{
332
- return `/guilds/${guildId}/members/@me`;
333
- },
334
- member: (guildId, userId)=>{
335
- return `/guilds/${guildId}/members/${userId}`;
336
- },
337
- members: (guildId, options)=>{
338
- let url = `/guilds/${guildId}/members?`;
339
- if (options !== undefined) {
340
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
341
- if (options.limit) url += `limit=${options.limit}`;
342
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
343
- if (options.after) url += `&after=${options.after}`;
344
- }
345
- return url;
346
- },
347
- search: (guildId, query, options)=>{
348
- let url = `/guilds/${guildId}/members/search?query=${encodeURIComponent(query)}`;
349
- if (options) {
350
- if (options.limit !== undefined) url += `&limit=${options.limit}`;
351
- }
352
- return url;
353
- },
354
- prune: (guildId, options)=>{
355
- let url = `/guilds/${guildId}/prune?`;
356
- if (options) {
357
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
358
- if (options.days) url += `days=${options.days}`;
359
- if (Array.isArray(options.includeRoles)) {
360
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
361
- url += `&include_roles=${options.includeRoles.join(',')}`;
362
- } else if (options.includeRoles) {
363
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
364
- url += `&include_roles=${options.includeRoles}`;
365
- }
366
- }
367
- return url;
368
- }
369
- },
370
- mfa: (guildId)=>`/guilds/${guildId}/mfa`,
371
- preview: (guildId)=>{
372
- return `/guilds/${guildId}/preview`;
373
- },
374
- prune: (guildId, options)=>{
375
- let url = `/guilds/${guildId}/prune?`;
376
- if (options) {
377
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
378
- if (options.days) url += `days=${options.days}`;
379
- if (Array.isArray(options.includeRoles)) {
380
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
381
- url += `&include_roles=${options.includeRoles.join(',')}`;
382
- } else if (options.includeRoles) {
383
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
384
- url += `&include_roles=${options.includeRoles}`;
385
- }
386
- }
387
- return url;
388
- },
389
- roles: {
390
- one: (guildId, roleId)=>{
391
- return `/guilds/${guildId}/roles/${roleId}`;
392
- },
393
- all: (guildId)=>{
394
- return `/guilds/${guildId}/roles`;
395
- },
396
- member: (guildId, memberId, roleId)=>{
397
- return `/guilds/${guildId}/members/${memberId}/roles/${roleId}`;
398
- }
399
- },
400
- stickers: (guildId)=>{
401
- return `/guilds/${guildId}/stickers`;
402
- },
403
- sticker: (guildId, stickerId)=>{
404
- return `/guilds/${guildId}/stickers/${stickerId}`;
405
- },
406
- voice: (guildId, userId)=>{
407
- return `/guilds/${guildId}/voice-states/${userId ?? '@me'}`;
408
- },
409
- templates: {
410
- code: (code)=>{
411
- return `/guilds/templates/${code}`;
412
- },
413
- guild: (guildId, code)=>{
414
- return `/guilds/${guildId}/templates/${code}`;
415
- },
416
- all: (guildId)=>{
417
- return `/guilds/${guildId}/templates`;
418
- }
419
- },
420
- vanity: (guildId)=>{
421
- return `/guilds/${guildId}/vanity-url`;
422
- },
423
- regions: (guildId)=>{
424
- return `/guilds/${guildId}/regions`;
425
- },
426
- webhooks: (guildId)=>{
427
- return `/guilds/${guildId}/webhooks`;
428
- },
429
- welcome: (guildId)=>{
430
- return `/guilds/${guildId}/welcome-screen`;
431
- },
432
- widget: (guildId)=>{
433
- return `/guilds/${guildId}/widget`;
434
- },
435
- widgetJson: (guildId)=>{
436
- return `/guilds/${guildId}/widget.json`;
437
- }
438
- },
439
- sticker: (stickerId)=>{
440
- return `/stickers/${stickerId}`;
441
- },
442
- regions: ()=>{
443
- return '/voice/regions';
444
- },
445
- // Interaction Endpoints
446
- interactions: {
447
- commands: {
448
- // Application Endpoints
449
- commands: (applicationId)=>{
450
- return `/applications/${applicationId}/commands`;
451
- },
452
- guilds: {
453
- all (applicationId, guildId) {
454
- return `/applications/${applicationId}/guilds/${guildId}/commands`;
455
- },
456
- one (applicationId, guildId, commandId, withLocalizations) {
457
- let url = `/applications/${applicationId}/guilds/${guildId}/commands/${commandId}?`;
458
- if (withLocalizations !== undefined) {
459
- url += `with_localizations=${withLocalizations.toString()}`;
460
- }
461
- return url;
462
- }
463
- },
464
- permissions: (applicationId, guildId)=>{
465
- return `/applications/${applicationId}/guilds/${guildId}/commands/permissions`;
466
- },
467
- permission: (applicationId, guildId, commandId)=>{
468
- return `/applications/${applicationId}/guilds/${guildId}/commands/${commandId}/permissions`;
469
- },
470
- command: (applicationId, commandId, withLocalizations)=>{
471
- let url = `/applications/${applicationId}/commands/${commandId}?`;
472
- if (withLocalizations !== undefined) {
473
- url += `withLocalizations=${withLocalizations.toString()}`;
474
- }
475
- return url;
476
- }
477
- },
478
- responses: {
479
- // Interaction Endpoints
480
- callback: (interactionId, token)=>{
481
- return `/interactions/${interactionId}/${token}/callback`;
482
- },
483
- original: (interactionId, token)=>{
484
- return `/webhooks/${interactionId}/${token}/messages/@original`;
485
- },
486
- message: (applicationId, token, messageId)=>{
487
- return `/webhooks/${applicationId}/${token}/messages/${messageId}`;
488
- }
489
- }
490
- },
491
- // User endpoints
492
- user (userId) {
493
- return `/users/${userId}`;
494
- },
495
- userBot () {
496
- return '/users/@me';
497
- },
498
- oauth2Application () {
499
- return 'oauth2/applications/@me';
500
- },
501
- gatewayBot () {
502
- return '/gateway/bot';
503
- },
504
- nitroStickerPacks () {
505
- return '/sticker-packs';
506
- }
507
- },
36
+ token: options.token,
37
+ version: options.version ?? DISCORD_API_VERSION,
38
+ routes: createRoutes(),
508
39
  checkRateLimits (url) {
509
40
  const ratelimited = rest.rateLimitedPaths.get(url);
510
41
  const global = rest.rateLimitedPaths.get('global');
@@ -549,10 +80,10 @@ export function createRestManager(options) {
549
80
  const headers = {
550
81
  'user-agent': `DiscordBot (https://github.com/discordeno/discordeno, v${version})`
551
82
  };
552
- if (!options?.unauthorized) headers.authorization = `Bot ${rest.token}`;
83
+ if (options?.unauthorized !== false) headers.authorization = `Bot ${rest.token}`;
553
84
  // IF A REASON IS PROVIDED ENCODE IT IN HEADERS
554
85
  if (options?.reason !== undefined) {
555
- headers['x-audit-log-reason'] = encodeURIComponent(options?.reason);
86
+ headers[AUDIT_LOG_REASON_HEADER] = encodeURIComponent(options?.reason);
556
87
  }
557
88
  let body;
558
89
  // TODO: check if we need to add specific check for GET method
@@ -618,13 +149,13 @@ export function createRestManager(options) {
618
149
  /** Processes the rate limit headers and determines if it needs to be rate limited and returns the bucket id if available */ processHeaders (url, headers) {
619
150
  let rateLimited = false;
620
151
  // GET ALL NECESSARY HEADERS
621
- const remaining = headers.get('x-ratelimit-remaining');
622
- const retryAfter = headers.get('x-ratelimit-reset-after');
152
+ const remaining = headers.get(RATE_LIMIT_REMAINING_HEADER);
153
+ const retryAfter = headers.get(RATE_LIMIT_RESET_AFTER_HEADER);
623
154
  const reset = Date.now() + Number(retryAfter) * 1000;
624
- const global = headers.get('x-ratelimit-global');
155
+ const global = headers.get(RATE_LIMIT_GLOBAL_HEADER);
625
156
  // undefined override null needed for typings
626
- const bucketId = headers.get('x-ratelimit-bucket') ?? undefined;
627
- const limit = headers.get('x-ratelimit-limit');
157
+ const bucketId = headers.get(RATE_LIMIT_BUCKET_HEADER) ?? undefined;
158
+ const limit = headers.get(RATE_LIMIT_LIMIT_HEADER);
628
159
  rest.queues.get(url)?.handleCompletedRequest({
629
160
  remaining: remaining ? Number(remaining) : undefined,
630
161
  interval: retryAfter ? Number(retryAfter) * 1000 : undefined,
@@ -679,7 +210,7 @@ export function createRestManager(options) {
679
210
  return rateLimited ? bucketId : undefined;
680
211
  },
681
212
  async sendRequest (options) {
682
- const url = options.url.startsWith('https://') ? options.url : `${rest.baseUrl}/v${rest.version}${options.url}`;
213
+ const url = `${rest.baseUrl}/v${rest.version}${options.route}`;
683
214
  const payload = rest.createRequestBody(options.method, options.requestBodyOptions);
684
215
  logger.debug(`sending request to ${url}`, 'with payload:', {
685
216
  ...payload,
@@ -691,46 +222,44 @@ export function createRestManager(options) {
691
222
  const response = await fetch(url, payload);
692
223
  logger.debug(`request fetched from ${url} with status ${response.status} & ${response.statusText}`);
693
224
  // Set the bucket id if it was available on the headers
694
- const bucketId = rest.processHeaders(rest.simplifyUrl(options.url, options.method), response.headers);
225
+ const bucketId = rest.processHeaders(rest.simplifyUrl(options.route, options.method), response.headers);
695
226
  if (bucketId) options.bucketId = bucketId;
696
227
  if (response.status < 200 || response.status >= 400) {
697
228
  logger.debug(`Request to ${url} failed.`);
698
- if (response.status === 429) {
699
- logger.debug(`Request to ${url} was ratelimited.`);
700
- // Too many attempts, get rid of request from queue.
701
- if (options.retryCount++ >= rest.maxRetryCount) {
702
- logger.debug(`Request to ${url} exceeded the maximum allowed retries.`, 'with payload:', payload);
703
- // rest.debug(`[REST - RetriesMaxed] ${JSON.stringify(options)}`)
704
- // Remove item from queue to prevent retry
705
- options.reject({
706
- ok: false,
707
- status: response.status,
708
- error: 'The options was rate limited and it maxed out the retries limit.'
709
- });
710
- return;
711
- }
712
- // Rate limited, add back to queue
713
- rest.invalidBucket.handleCompletedRequest(response.status, response.headers.get('X-RateLimit-Scope') === 'shared');
714
- const resetAfter = response.headers.get('x-ratelimit-reset-after');
715
- if (resetAfter) await delay(Number(resetAfter) * 1000);
716
- // process the response to prevent mem leak
717
- await response.json();
718
- return await options.retryRequest?.(options);
229
+ if (response.status !== 429) {
230
+ options.reject({
231
+ ok: false,
232
+ status: response.status,
233
+ body: await response.text()
234
+ });
235
+ return;
719
236
  }
720
- options.reject({
721
- ok: false,
722
- status: response.status,
723
- body: JSON.stringify(await response.json())
724
- });
725
- return;
237
+ logger.debug(`Request to ${url} was ratelimited.`);
238
+ // Too many attempts, get rid of request from queue.
239
+ if (options.retryCount >= rest.maxRetryCount) {
240
+ logger.debug(`Request to ${url} exceeded the maximum allowed retries.`, 'with payload:', payload);
241
+ // rest.debug(`[REST - RetriesMaxed] ${JSON.stringify(options)}`)
242
+ options.reject({
243
+ ok: false,
244
+ status: response.status,
245
+ error: 'The request was rate limited and it maxed out the retries limit.'
246
+ });
247
+ return;
248
+ }
249
+ options.retryCount += 1;
250
+ // Rate limited, add back to queue
251
+ rest.invalidBucket.handleCompletedRequest(response.status, response.headers.get(RATE_LIMIT_SCOPE_HEADER) === 'shared');
252
+ const resetAfter = response.headers.get(RATE_LIMIT_RESET_AFTER_HEADER);
253
+ if (resetAfter) await delay(Number(resetAfter) * 1000);
254
+ // process the response to prevent mem leak
255
+ await response.arrayBuffer();
256
+ return await options.retryRequest?.(options);
726
257
  }
727
- const is204 = response.status === 204;
728
- const json = is204 ? undefined : await response.json();
729
- // Discord sometimes sends no response with 204 code
258
+ // Discord sometimes sends no response with no content.
730
259
  options.resolve({
731
260
  ok: true,
732
261
  status: response.status,
733
- body: JSON.stringify(json)
262
+ body: response.status === 204 ? undefined : await response.text()
734
263
  });
735
264
  },
736
265
  simplifyUrl (url, method) {
@@ -754,16 +283,12 @@ export function createRestManager(options) {
754
283
  }
755
284
  return parts.join('/');
756
285
  },
757
- processRequest (request) {
758
- const route = request.url.substring(request.url.indexOf('api/'));
759
- const parts = route.split('/');
760
- // Remove the api/
761
- parts.shift();
762
- // Removes the /v#/
763
- if (parts[0]?.startsWith('v')) parts.shift();
764
- // Set the full url to discord api in case it was recieved in a proxy rest
765
- request.url = `${rest.baseUrl}/v${rest.version}/${parts.join('/')}`;
766
- const url = rest.simplifyUrl(request.url, request.method);
286
+ async processRequest (request) {
287
+ const url = rest.simplifyUrl(request.route, request.method);
288
+ if (request.runThroughQueue === false) {
289
+ await rest.sendRequest(request);
290
+ return;
291
+ }
767
292
  const queue = rest.queues.get(url);
768
293
  if (queue !== undefined) {
769
294
  queue.makeRequest(request);
@@ -779,36 +304,14 @@ export function createRestManager(options) {
779
304
  rest.queues.set(url, bucketQueue);
780
305
  }
781
306
  },
782
- async makeRequest (method, url, options) {
783
- if (!rest.baseUrl.startsWith('https://discord.com') && url[0] === '/') {
784
- // Special handling for sending blobs across http to proxy
785
- // TODO: fix this hacky handling
786
- if (!(options?.body instanceof FormData) && !Array.isArray(options?.body) && options?.body?.file) {
787
- if (!Array.isArray(options.body.file)) {
788
- options.body.file = [
789
- options.body.file
790
- ];
791
- }
792
- // convert blobs to string before sending to proxy
793
- options.body.file = await Promise.all(options.body.file.map(async (f)=>{
794
- const url = encode(await f.blob.arrayBuffer());
795
- return {
796
- name: f.name,
797
- blob: `data:${f.blob.type};base64,${url}`
798
- };
799
- }));
307
+ async makeRequest (method, route, options) {
308
+ if (rest.isProxied) {
309
+ if (rest.authorization !== undefined) {
310
+ options ??= {};
311
+ options.headers ??= {};
312
+ options.headers.authorization = rest.authorization;
800
313
  }
801
- const headers = {
802
- Authorization: rest.authorization ?? ''
803
- };
804
- if (options?.body) {
805
- headers['Content-Type'] = 'application/json';
806
- }
807
- const result = await fetch(`${rest.baseUrl}${url}`, {
808
- body: options?.body ? JSON.stringify(options.body) : undefined,
809
- headers,
810
- method
811
- });
314
+ const result = await fetch(`${rest.baseUrl}/v${rest.version}${route}`, rest.createRequestBody(method, options));
812
315
  if (!result.ok) {
813
316
  const err = await result.json().catch(()=>{});
814
317
  // Legacy Handling to not break old code or when body is missing
@@ -817,21 +320,23 @@ export function createRestManager(options) {
817
320
  }
818
321
  return result.status !== 204 ? await result.json() : undefined;
819
322
  }
820
- return await new Promise((resolve, reject)=>{
323
+ // eslint-disable-next-line no-async-promise-executor
324
+ return await new Promise(async (resolve, reject)=>{
821
325
  const payload = {
822
- url,
326
+ route,
823
327
  method,
824
328
  requestBodyOptions: options,
825
329
  retryCount: 0,
826
330
  retryRequest: async function(payload) {
827
- rest.processRequest(payload);
331
+ await rest.processRequest(payload);
828
332
  },
829
333
  resolve: (data)=>{
830
334
  resolve(data.status !== 204 ? JSON.parse(data.body ?? '{}') : undefined);
831
335
  },
832
- reject
336
+ reject,
337
+ runThroughQueue: options?.runThroughQueue
833
338
  };
834
- rest.processRequest(payload);
339
+ await rest.processRequest(payload);
835
340
  });
836
341
  },
837
342
  async get (url, options) {
@@ -872,19 +377,22 @@ export function createRestManager(options) {
872
377
  async addThreadMember (channelId, userId) {
873
378
  await rest.put(rest.routes.channels.threads.user(channelId, userId));
874
379
  },
875
- async createAutomodRule (guildId, body) {
380
+ async createAutomodRule (guildId, body, reason) {
876
381
  return await rest.post(rest.routes.guilds.automod.rules(guildId), {
877
- body
382
+ body,
383
+ reason
878
384
  });
879
385
  },
880
- async createChannel (guildId, body) {
386
+ async createChannel (guildId, body, reason) {
881
387
  return await rest.post(rest.routes.guilds.channels(guildId), {
882
- body
388
+ body,
389
+ reason
883
390
  });
884
391
  },
885
- async createEmoji (guildId, body) {
392
+ async createEmoji (guildId, body, reason) {
886
393
  return await rest.post(rest.routes.guilds.emojis(guildId), {
887
- body
394
+ body,
395
+ reason
888
396
  });
889
397
  },
890
398
  async createGlobalApplicationCommand (body) {
@@ -910,14 +418,15 @@ export function createRestManager(options) {
910
418
  body
911
419
  });
912
420
  },
913
- async createGuildSticker (guildId, options) {
421
+ async createGuildSticker (guildId, options, reason) {
914
422
  const form = new FormData();
915
423
  form.append('file', options.file.blob, options.file.name);
916
424
  form.append('name', options.name);
917
425
  form.append('description', options.description);
918
426
  form.append('tags', options.tags);
919
427
  return await rest.post(rest.routes.guilds.stickers(guildId), {
920
- body: form
428
+ body: form,
429
+ reason
921
430
  });
922
431
  },
923
432
  async createGuildTemplate (guildId, body) {
@@ -925,15 +434,17 @@ export function createRestManager(options) {
925
434
  body
926
435
  });
927
436
  },
928
- async createForumThread (channelId, body) {
437
+ async createForumThread (channelId, body, reason) {
929
438
  return await rest.post(rest.routes.channels.forum(channelId), {
930
439
  body,
931
- files: body.files
440
+ files: body.files,
441
+ reason
932
442
  });
933
443
  },
934
- async createInvite (channelId, body = {}) {
444
+ async createInvite (channelId, body = {}, reason) {
935
445
  return await rest.post(rest.routes.channels.invites(channelId), {
936
- body
446
+ body,
447
+ reason
937
448
  });
938
449
  },
939
450
  async createRole (guildId, body, reason) {
@@ -942,14 +453,16 @@ export function createRestManager(options) {
942
453
  reason
943
454
  });
944
455
  },
945
- async createScheduledEvent (guildId, body) {
456
+ async createScheduledEvent (guildId, body, reason) {
946
457
  return await rest.post(rest.routes.guilds.events.events(guildId), {
947
- body
458
+ body,
459
+ reason
948
460
  });
949
461
  },
950
- async createStageInstance (body) {
462
+ async createStageInstance (body, reason) {
951
463
  return await rest.post(rest.routes.channels.stages(), {
952
- body
464
+ body,
465
+ reason
953
466
  });
954
467
  },
955
468
  async createWebhook (channelId, options, reason) {
@@ -982,7 +495,9 @@ export function createRestManager(options) {
982
495
  });
983
496
  },
984
497
  async deleteFollowupMessage (token, messageId) {
985
- await rest.delete(rest.routes.interactions.responses.message(rest.applicationId, token, messageId));
498
+ await rest.delete(rest.routes.interactions.responses.message(rest.applicationId, token, messageId), {
499
+ unauthorized: true
500
+ });
986
501
  },
987
502
  async deleteGlobalApplicationCommand (commandId) {
988
503
  await rest.delete(rest.routes.interactions.commands.command(rest.applicationId, commandId));
@@ -1001,8 +516,10 @@ export function createRestManager(options) {
1001
516
  async deleteGuildTemplate (guildId, templateCode) {
1002
517
  await rest.delete(rest.routes.guilds.templates.guild(guildId, templateCode));
1003
518
  },
1004
- async deleteIntegration (guildId, integrationId) {
1005
- await rest.delete(rest.routes.guilds.integration(guildId, integrationId));
519
+ async deleteIntegration (guildId, integrationId, reason) {
520
+ await rest.delete(rest.routes.guilds.integration(guildId, integrationId), {
521
+ reason
522
+ });
1006
523
  },
1007
524
  async deleteInvite (inviteCode, reason) {
1008
525
  await rest.delete(rest.routes.guilds.invite(inviteCode), {
@@ -1023,7 +540,9 @@ export function createRestManager(options) {
1023
540
  });
1024
541
  },
1025
542
  async deleteOriginalInteractionResponse (token) {
1026
- await rest.delete(rest.routes.interactions.responses.original(rest.applicationId, token));
543
+ await rest.delete(rest.routes.interactions.responses.original(rest.applicationId, token), {
544
+ unauthorized: true
545
+ });
1027
546
  },
1028
547
  async deleteOwnReaction (channelId, messageId, reaction) {
1029
548
  reaction = processReactionString(reaction);
@@ -1036,8 +555,10 @@ export function createRestManager(options) {
1036
555
  reaction = processReactionString(reaction);
1037
556
  await rest.delete(rest.routes.channels.reactions.emoji(channelId, messageId, reaction));
1038
557
  },
1039
- async deleteRole (guildId, roleId) {
1040
- await rest.delete(rest.routes.guilds.roles.one(guildId, roleId));
558
+ async deleteRole (guildId, roleId, reason) {
559
+ await rest.delete(rest.routes.guilds.roles.one(guildId, roleId), {
560
+ reason
561
+ });
1041
562
  },
1042
563
  async deleteScheduledEvent (guildId, eventId) {
1043
564
  await rest.delete(rest.routes.guilds.events.event(guildId, eventId));
@@ -1072,9 +593,10 @@ export function createRestManager(options) {
1072
593
  }
1073
594
  });
1074
595
  },
1075
- async editAutomodRule (guildId, ruleId, body) {
596
+ async editAutomodRule (guildId, ruleId, body, reason) {
1076
597
  return await rest.patch(rest.routes.guilds.automod.rule(guildId, ruleId), {
1077
- body
598
+ body,
599
+ reason
1078
600
  });
1079
601
  },
1080
602
  async editBotProfile (options) {
@@ -1086,14 +608,16 @@ export function createRestManager(options) {
1086
608
  }
1087
609
  });
1088
610
  },
1089
- async editChannel (channelId, body) {
611
+ async editChannel (channelId, body, reason) {
1090
612
  return await rest.patch(rest.routes.channels.channel(channelId), {
1091
- body
613
+ body,
614
+ reason
1092
615
  });
1093
616
  },
1094
- async editChannelPermissionOverrides (channelId, body) {
617
+ async editChannelPermissionOverrides (channelId, body, reason) {
1095
618
  await rest.put(rest.routes.channels.overwrite(channelId, body.id), {
1096
- body
619
+ body,
620
+ reason
1097
621
  });
1098
622
  },
1099
623
  async editChannelPositions (guildId, body) {
@@ -1101,15 +625,17 @@ export function createRestManager(options) {
1101
625
  body
1102
626
  });
1103
627
  },
1104
- async editEmoji (guildId, id, body) {
628
+ async editEmoji (guildId, id, body, reason) {
1105
629
  return await rest.patch(rest.routes.guilds.emoji(guildId, id), {
1106
- body
630
+ body,
631
+ reason
1107
632
  });
1108
633
  },
1109
634
  async editFollowupMessage (token, messageId, body) {
1110
635
  return await rest.patch(rest.routes.interactions.responses.message(rest.applicationId, token, messageId), {
1111
636
  body,
1112
- files: body.files
637
+ files: body.files,
638
+ unauthorized: true
1113
639
  });
1114
640
  },
1115
641
  async editGlobalApplicationCommand (commandId, body) {
@@ -1117,9 +643,10 @@ export function createRestManager(options) {
1117
643
  body
1118
644
  });
1119
645
  },
1120
- async editGuild (guildId, body) {
646
+ async editGuild (guildId, body, reason) {
1121
647
  return await rest.patch(rest.routes.guilds.guild(guildId), {
1122
- body
648
+ body,
649
+ reason
1123
650
  });
1124
651
  },
1125
652
  async editGuildApplicationCommand (commandId, guildId, body) {
@@ -1135,9 +662,10 @@ export function createRestManager(options) {
1135
662
  reason
1136
663
  });
1137
664
  },
1138
- async editGuildSticker (guildId, stickerId, body) {
665
+ async editGuildSticker (guildId, stickerId, body, reason) {
1139
666
  return await rest.patch(rest.routes.guilds.sticker(guildId, stickerId), {
1140
- body
667
+ body,
668
+ reason
1141
669
  });
1142
670
  },
1143
671
  async editGuildTemplate (guildId, templateCode, body) {
@@ -1162,7 +690,8 @@ export function createRestManager(options) {
1162
690
  type: InteractionResponseTypes.UpdateMessage,
1163
691
  data: options
1164
692
  },
1165
- files: options.files
693
+ files: options.files,
694
+ unauthorized: true
1166
695
  });
1167
696
  },
1168
697
  async editOwnVoiceState (guildId, options) {
@@ -1173,19 +702,22 @@ export function createRestManager(options) {
1173
702
  }
1174
703
  });
1175
704
  },
1176
- async editScheduledEvent (guildId, eventId, body) {
705
+ async editScheduledEvent (guildId, eventId, body, reason) {
1177
706
  return await rest.patch(rest.routes.guilds.events.event(guildId, eventId), {
1178
- body
707
+ body,
708
+ reason
1179
709
  });
1180
710
  },
1181
- async editRole (guildId, roleId, body) {
711
+ async editRole (guildId, roleId, body, reason) {
1182
712
  return await rest.patch(rest.routes.guilds.roles.one(guildId, roleId), {
1183
- body
713
+ body,
714
+ reason
1184
715
  });
1185
716
  },
1186
- async editRolePositions (guildId, body) {
717
+ async editRolePositions (guildId, body, reason) {
1187
718
  return await rest.patch(rest.routes.guilds.roles.all(guildId), {
1188
- body
719
+ body,
720
+ reason
1189
721
  });
1190
722
  },
1191
723
  async editStageInstance (channelId, topic, reason) {
@@ -1201,9 +733,10 @@ export function createRestManager(options) {
1201
733
  body: options
1202
734
  });
1203
735
  },
1204
- async editWebhook (webhookId, body) {
736
+ async editWebhook (webhookId, body, reason) {
1205
737
  return await rest.patch(rest.routes.webhooks.id(webhookId), {
1206
- body
738
+ body,
739
+ reason
1207
740
  });
1208
741
  },
1209
742
  async editWebhookMessage (webhookId, token, messageId, options) {
@@ -1217,14 +750,16 @@ export function createRestManager(options) {
1217
750
  body
1218
751
  });
1219
752
  },
1220
- async editWelcomeScreen (guildId, body) {
753
+ async editWelcomeScreen (guildId, body, reason) {
1221
754
  return await rest.patch(rest.routes.guilds.welcome(guildId), {
1222
- body
755
+ body,
756
+ reason
1223
757
  });
1224
758
  },
1225
- async editWidgetSettings (guildId, body) {
759
+ async editWidgetSettings (guildId, body, reason) {
1226
760
  return await rest.patch(rest.routes.guilds.widget(guildId), {
1227
- body
761
+ body,
762
+ reason
1228
763
  });
1229
764
  },
1230
765
  async executeWebhook (webhookId, token, options) {
@@ -1295,7 +830,9 @@ export function createRestManager(options) {
1295
830
  return await rest.get(rest.routes.guilds.emojis(guildId));
1296
831
  },
1297
832
  async getFollowupMessage (token, messageId) {
1298
- return await rest.get(rest.routes.interactions.responses.message(rest.applicationId, token, messageId));
833
+ return await rest.get(rest.routes.interactions.responses.message(rest.applicationId, token, messageId), {
834
+ unauthorized: true
835
+ });
1299
836
  },
1300
837
  async getGatewayBot () {
1301
838
  return await rest.get(rest.routes.gatewayBot());
@@ -1348,7 +885,9 @@ export function createRestManager(options) {
1348
885
  return await rest.get(rest.routes.nitroStickerPacks());
1349
886
  },
1350
887
  async getOriginalInteractionResponse (token) {
1351
- return await rest.get(rest.routes.interactions.responses.original(rest.applicationId, token));
888
+ return await rest.get(rest.routes.interactions.responses.original(rest.applicationId, token), {
889
+ unauthorized: true
890
+ });
1352
891
  },
1353
892
  async getPinnedMessages (channelId) {
1354
893
  return await rest.get(rest.routes.channels.pins(channelId));
@@ -1448,47 +987,19 @@ export function createRestManager(options) {
1448
987
  async removeThreadMember (channelId, userId) {
1449
988
  await rest.delete(rest.routes.channels.threads.user(channelId, userId));
1450
989
  },
1451
- // TODO: why that
1452
990
  async sendFollowupMessage (token, options) {
1453
- return await new Promise((resolve, reject)=>{
1454
- rest.sendRequest({
1455
- url: rest.routes.webhooks.webhook(rest.applicationId, token),
1456
- method: 'POST',
1457
- requestBodyOptions: {
1458
- body: options,
1459
- files: options.files
1460
- },
1461
- retryCount: 0,
1462
- retryRequest: async function(options) {
1463
- // TODO: should change to reprocess queue item
1464
- await rest.sendRequest(options);
1465
- },
1466
- resolve: (data)=>{
1467
- resolve(data.status !== 204 ? JSON.parse(data.body ?? '{}') : undefined);
1468
- },
1469
- reject
1470
- });
991
+ return await rest.post(rest.routes.webhooks.webhook(rest.applicationId, token), {
992
+ body: options,
993
+ files: options.files,
994
+ unauthorized: true
1471
995
  });
1472
996
  },
1473
- // TODO: why that
1474
997
  async sendInteractionResponse (interactionId, token, options) {
1475
- await new Promise((resolve, reject)=>{
1476
- rest.sendRequest({
1477
- url: rest.routes.interactions.responses.callback(interactionId, token),
1478
- method: 'POST',
1479
- requestBodyOptions: {
1480
- body: options
1481
- },
1482
- retryCount: 0,
1483
- retryRequest: async function(options) {
1484
- // TODO: should change to reprocess queue item
1485
- await rest.sendRequest(options);
1486
- },
1487
- resolve: (data)=>{
1488
- resolve(data.status !== 204 ? JSON.parse(data.body ?? '{}') : undefined);
1489
- },
1490
- reject
1491
- });
998
+ return await rest.post(rest.routes.interactions.responses.callback(interactionId, token), {
999
+ body: options,
1000
+ files: options.data?.files,
1001
+ runThroughQueue: false,
1002
+ unauthorized: true
1492
1003
  });
1493
1004
  },
1494
1005
  async sendMessage (channelId, body) {
@@ -1497,32 +1008,37 @@ export function createRestManager(options) {
1497
1008
  files: body.files
1498
1009
  });
1499
1010
  },
1500
- async startThreadWithMessage (channelId, messageId, body) {
1011
+ async startThreadWithMessage (channelId, messageId, body, reason) {
1501
1012
  return await rest.post(rest.routes.channels.threads.message(channelId, messageId), {
1502
- body
1013
+ body,
1014
+ reason
1503
1015
  });
1504
1016
  },
1505
- async startThreadWithoutMessage (channelId, body) {
1017
+ async startThreadWithoutMessage (channelId, body, reason) {
1506
1018
  return await rest.post(rest.routes.channels.threads.all(channelId), {
1507
- body
1019
+ body,
1020
+ reason
1508
1021
  });
1509
1022
  },
1510
1023
  async syncGuildTemplate (guildId) {
1511
1024
  return await rest.put(rest.routes.guilds.templates.all(guildId));
1512
1025
  },
1513
- async banMember (guildId, userId, body) {
1026
+ async banMember (guildId, userId, body, reason) {
1514
1027
  await rest.put(rest.routes.guilds.members.ban(guildId, userId), {
1515
- body
1028
+ body,
1029
+ reason
1516
1030
  });
1517
1031
  },
1518
- async editBotMember (guildId, body) {
1032
+ async editBotMember (guildId, body, reason) {
1519
1033
  return await rest.patch(rest.routes.guilds.members.bot(guildId), {
1520
- body
1034
+ body,
1035
+ reason
1521
1036
  });
1522
1037
  },
1523
- async editMember (guildId, userId, body) {
1038
+ async editMember (guildId, userId, body, reason) {
1524
1039
  return await rest.patch(rest.routes.guilds.members.member(guildId, userId), {
1525
- body
1040
+ body,
1041
+ reason
1526
1042
  });
1527
1043
  },
1528
1044
  async getMember (guildId, userId) {
@@ -1541,16 +1057,19 @@ export function createRestManager(options) {
1541
1057
  reason
1542
1058
  });
1543
1059
  },
1544
- async pruneMembers (guildId, body) {
1060
+ async pruneMembers (guildId, body, reason) {
1545
1061
  return await rest.post(rest.routes.guilds.members.prune(guildId), {
1546
- body
1062
+ body,
1063
+ reason
1547
1064
  });
1548
1065
  },
1549
1066
  async searchMembers (guildId, query, options) {
1550
1067
  return await rest.get(rest.routes.guilds.members.search(guildId, query, options));
1551
1068
  },
1552
- async unbanMember (guildId, userId) {
1553
- await rest.delete(rest.routes.guilds.members.ban(guildId, userId));
1069
+ async unbanMember (guildId, userId, reason) {
1070
+ await rest.delete(rest.routes.guilds.members.ban(guildId, userId), {
1071
+ reason
1072
+ });
1554
1073
  },
1555
1074
  async unpinMessage (channelId, messageId, reason) {
1556
1075
  await rest.delete(rest.routes.channels.pin(channelId, messageId), {
@@ -1573,5 +1092,12 @@ export function createRestManager(options) {
1573
1092
  };
1574
1093
  return rest;
1575
1094
  }
1095
+ var HttpResponseCode;
1096
+ (function(HttpResponseCode) {
1097
+ HttpResponseCode[HttpResponseCode[/** Minimum value of a code in oder to consider that it was successful. */ "Success"] = 200] = "Success";
1098
+ HttpResponseCode[HttpResponseCode[/** Request completed successfully, but Discord returned an empty body. */ "NoContent"] = 204] = "NoContent";
1099
+ HttpResponseCode[HttpResponseCode[/** Minimum value of a code in order to consider that something went wrong. */ "Error"] = 400] = "Error";
1100
+ HttpResponseCode[HttpResponseCode[/** This request got rate limited. */ "TooManyRequests"] = 429] = "TooManyRequests";
1101
+ })(HttpResponseCode || (HttpResponseCode = {}));
1576
1102
 
1577
1103
  //# sourceMappingURL=manager.js.map