@discordeno/rest 19.0.0-next.fc13bdf → 19.0.0-next.fd518cb

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,506 +1,40 @@
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, findFiles, 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 { createInvalidRequestBucket } from './invalidBucket.js';
4
4
  import { Queue } from './queue.js';
5
+ import { createRoutes } from './routes.js';
5
6
  // TODO: make dynamic based on package.json file
6
7
  const version = '19.0.0-alpha.1';
8
+ export const DISCORD_API_VERSION = 10;
9
+ export const DISCORD_API_URL = 'https://discord.com/api';
10
+ export const AUDIT_LOG_REASON_HEADER = 'x-audit-log-reason';
11
+ export const RATE_LIMIT_REMAINING_HEADER = 'x-ratelimit-remaining';
12
+ export const RATE_LIMIT_RESET_AFTER_HEADER = 'x-ratelimit-reset-after';
13
+ export const RATE_LIMIT_GLOBAL_HEADER = 'x-ratelimit-global';
14
+ export const RATE_LIMIT_BUCKET_HEADER = 'x-ratelimit-bucket';
15
+ export const RATE_LIMIT_LIMIT_HEADER = 'x-ratelimit-limit';
16
+ export const RATE_LIMIT_SCOPE_HEADER = 'x-ratelimit-scope';
7
17
  export function createRestManager(options) {
8
- // Falsy token string check
9
- if (!options.token) throw new Error('You must provide a valid token.');
18
+ const applicationId = options.applicationId ? BigInt(options.applicationId) : options.token ? getBotIdFromToken(options.token) : undefined;
19
+ if (!applicationId) {
20
+ 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.');
21
+ }
22
+ const baseUrl = options.proxy?.baseUrl ?? DISCORD_API_URL;
10
23
  const rest = {
11
- token: options.token,
12
- applicationId: options.applicationId ? BigInt(options.applicationId) : getBotIdFromToken(options.token),
13
- version: options.version ?? 10,
14
- baseUrl: options.baseUrl ?? 'https://discord.com/api',
15
- maxRetryCount: Infinity,
24
+ applicationId,
25
+ authorization: options.proxy?.authorization,
26
+ baseUrl,
27
+ deleteQueueDelay: 60000,
16
28
  globallyRateLimited: false,
29
+ invalidBucket: createInvalidRequestBucket({}),
30
+ isProxied: !baseUrl.startsWith(DISCORD_API_URL),
31
+ maxRetryCount: Infinity,
17
32
  processingRateLimitedPaths: false,
18
- deleteQueueDelay: 60000,
19
33
  queues: new Map(),
20
34
  rateLimitedPaths: new Map(),
21
- invalidBucket: createInvalidRequestBucket({}),
22
- routes: {
23
- webhooks: {
24
- id: (webhookId)=>{
25
- return `/webhooks/${webhookId}`;
26
- },
27
- message: (webhookId, token, messageId, options)=>{
28
- let url = `/webhooks/${webhookId}/${token}/messages/${messageId}?`;
29
- if (options) {
30
- if (options.threadId) url += `thread_id=${options.threadId}`;
31
- }
32
- return url;
33
- },
34
- original: (webhookId, token, options)=>{
35
- let url = `/webhooks/${webhookId}/${token}/messages/@original?`;
36
- if (options) {
37
- if (options.threadId) url += `thread_id=${options.threadId}`;
38
- }
39
- return url;
40
- },
41
- webhook: (webhookId, token, options)=>{
42
- let url = `/webhooks/${webhookId}/${token}?`;
43
- if (options) {
44
- if (options?.wait !== undefined) url += `wait=${options.wait.toString()}`;
45
- if (options.threadId) url += `thread_id=${options.threadId}`;
46
- }
47
- return url;
48
- }
49
- },
50
- // Miscellaneous Endpoints
51
- sessionInfo: ()=>rest.routes.gatewayBot(),
52
- // Channel Endpoints
53
- channels: {
54
- bulk: (channelId)=>{
55
- return `/channels/${channelId}/messages/bulk-delete`;
56
- },
57
- dm: ()=>{
58
- return '/users/@me/channels';
59
- },
60
- pin: (channelId, messageId)=>{
61
- return `/channels/${channelId}/pins/${messageId}`;
62
- },
63
- pins: (channelId)=>{
64
- return `/channels/${channelId}/pins`;
65
- },
66
- reactions: {
67
- bot: (channelId, messageId, emoji)=>{
68
- return `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}/@me`;
69
- },
70
- user: (channelId, messageId, emoji, userId)=>{
71
- return `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}/${userId}`;
72
- },
73
- all: (channelId, messageId)=>{
74
- return `/channels/${channelId}/messages/${messageId}/reactions`;
75
- },
76
- emoji: (channelId, messageId, emoji, options)=>{
77
- let url = `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}?`;
78
- if (options) {
79
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
80
- if (options.after) url += `after=${options.after}`;
81
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
82
- if (options.limit) url += `&limit=${options.limit}`;
83
- }
84
- return url;
85
- },
86
- message: (channelId, messageId, emoji, options)=>{
87
- let url = `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}?`;
88
- if (options) {
89
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
90
- if (options.after) url += `after=${options.after}`;
91
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
92
- if (options.limit) url += `&limit=${options.limit}`;
93
- }
94
- return url;
95
- }
96
- },
97
- webhooks: (channelId)=>{
98
- return `/channels/${channelId}/webhooks`;
99
- },
100
- channel: (channelId)=>{
101
- return `/channels/${channelId}`;
102
- },
103
- follow: (channelId)=>{
104
- return `/channels/${channelId}/followers`;
105
- },
106
- forum: (channelId)=>{
107
- return `/channels/${channelId}/threads?has_message=true`;
108
- },
109
- invites: (channelId)=>{
110
- return `/channels/${channelId}/invites`;
111
- },
112
- message: (channelId, messageId)=>{
113
- return `/channels/${channelId}/messages/${messageId}`;
114
- },
115
- messages: (channelId, options)=>{
116
- let url = `/channels/${channelId}/messages?`;
117
- if (options) {
118
- if (isGetMessagesAfter(options) && options.after) {
119
- url += `after=${options.after}`;
120
- }
121
- if (isGetMessagesBefore(options) && options.before) {
122
- url += `&before=${options.before}`;
123
- }
124
- if (isGetMessagesAround(options) && options.around) {
125
- url += `&around=${options.around}`;
126
- }
127
- if (isGetMessagesLimit(options) && options.limit) {
128
- url += `&limit=${options.limit}`;
129
- }
130
- }
131
- return url;
132
- },
133
- overwrite: (channelId, overwriteId)=>{
134
- return `/channels/${channelId}/permissions/${overwriteId}`;
135
- },
136
- crosspost: (channelId, messageId)=>{
137
- return `/channels/${channelId}/messages/${messageId}/crosspost`;
138
- },
139
- stages: ()=>{
140
- return '/stage-instances';
141
- },
142
- stage: (channelId)=>{
143
- return `/stage-instances/${channelId}`;
144
- },
145
- // Thread Endpoints
146
- threads: {
147
- message: (channelId, messageId)=>{
148
- return `/channels/${channelId}/messages/${messageId}/threads`;
149
- },
150
- all: (channelId)=>{
151
- return `/channels/${channelId}/threads`;
152
- },
153
- active: (guildId)=>{
154
- return `/guilds/${guildId}/threads/active`;
155
- },
156
- members: (channelId)=>{
157
- return `/channels/${channelId}/thread-members`;
158
- },
159
- me: (channelId)=>{
160
- return `/channels/${channelId}/thread-members/@me`;
161
- },
162
- user: (channelId, userId)=>{
163
- return `/channels/${channelId}/thread-members/${userId}`;
164
- },
165
- archived: (channelId)=>{
166
- return `/channels/${channelId}/threads/archived`;
167
- },
168
- public: (channelId, options)=>{
169
- let url = `/channels/${channelId}/threads/archived/public?`;
170
- if (options) {
171
- if (options.before) {
172
- url += `before=${new Date(options.before).toISOString()}`;
173
- }
174
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
175
- if (options.limit) url += `&limit=${options.limit}`;
176
- }
177
- return url;
178
- },
179
- private: (channelId, options)=>{
180
- let url = `/channels/${channelId}/threads/archived/private?`;
181
- if (options) {
182
- if (options.before) {
183
- url += `before=${new Date(options.before).toISOString()}`;
184
- }
185
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
186
- if (options.limit) url += `&limit=${options.limit}`;
187
- }
188
- return url;
189
- },
190
- joined: (channelId, options)=>{
191
- let url = `/channels/${channelId}/users/@me/threads/archived/private?`;
192
- if (options) {
193
- if (options.before) {
194
- url += `before=${new Date(options.before).toISOString()}`;
195
- }
196
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
197
- if (options.limit) url += `&limit=${options.limit}`;
198
- }
199
- return url;
200
- }
201
- },
202
- typing: (channelId)=>{
203
- return `/channels/${channelId}/typing`;
204
- }
205
- },
206
- // Guild Endpoints
207
- guilds: {
208
- all: ()=>{
209
- return '/guilds';
210
- },
211
- auditlogs: (guildId, options)=>{
212
- let url = `/guilds/${guildId}/audit-logs?`;
213
- if (options) {
214
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
215
- if (options.actionType) url += `action_type=${options.actionType}`;
216
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
217
- if (options.before) url += `&before=${options.before}`;
218
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
219
- if (options.limit) url += `&limit=${options.limit}`;
220
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
221
- if (options.userId) url += `&user_id=${options.userId}`;
222
- }
223
- return url;
224
- },
225
- automod: {
226
- rule: (guildId, ruleId)=>{
227
- return `/guilds/${guildId}/auto-moderation/rules/${ruleId}`;
228
- },
229
- rules: (guildId)=>{
230
- return `/guilds/${guildId}/auto-moderation/rules`;
231
- }
232
- },
233
- channels: (guildId)=>{
234
- return `/guilds/${guildId}/channels`;
235
- },
236
- emoji: (guildId, emojiId)=>{
237
- return `/guilds/${guildId}/emojis/${emojiId}`;
238
- },
239
- emojis: (guildId)=>{
240
- return `/guilds/${guildId}/emojis`;
241
- },
242
- events: {
243
- events: (guildId, withUserCount)=>{
244
- let url = `/guilds/${guildId}/scheduled-events?`;
245
- if (withUserCount !== undefined) {
246
- url += `with_user_count=${withUserCount.toString()}`;
247
- }
248
- return url;
249
- },
250
- event: (guildId, eventId, withUserCount)=>{
251
- let url = `/guilds/${guildId}/scheduled-events/${eventId}`;
252
- if (withUserCount !== undefined) {
253
- url += `with_user_count=${withUserCount.toString()}`;
254
- }
255
- return url;
256
- },
257
- users: (guildId, eventId, options)=>{
258
- let url = `/guilds/${guildId}/scheduled-events/${eventId}/users?`;
259
- if (options) {
260
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
261
- if (options.limit !== undefined) url += `limit=${options.limit}`;
262
- if (options.withMember !== undefined) {
263
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
264
- url += `&with_member=${options.withMember.toString()}`;
265
- }
266
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
267
- if (options.after !== undefined) url += `&after=${options.after}`;
268
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
269
- if (options.before !== undefined) url += `&before=${options.before}`;
270
- }
271
- return url;
272
- }
273
- },
274
- guild (guildId, withCounts) {
275
- let url = `/guilds/${guildId}?`;
276
- if (withCounts !== undefined) {
277
- url += `with_counts=${withCounts.toString()}`;
278
- }
279
- return url;
280
- },
281
- integration (guildId, integrationId) {
282
- return `/guilds/${guildId}/integrations/${integrationId}`;
283
- },
284
- integrations: (guildId)=>{
285
- return `/guilds/${guildId}/integrations?include_applications=true`;
286
- },
287
- invite (inviteCode, options) {
288
- let url = `/invites/${inviteCode}?`;
289
- if (options) {
290
- if (options.withCounts !== undefined) {
291
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
292
- url += `with_counts=${options.withCounts.toString()}`;
293
- }
294
- if (options.withExpiration !== undefined) {
295
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
296
- url += `&with_expiration=${options.withExpiration.toString()}`;
297
- }
298
- if (options.scheduledEventId) {
299
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
300
- url += `&guild_scheduled_event_id=${options.scheduledEventId}`;
301
- }
302
- }
303
- return url;
304
- },
305
- invites: (guildId)=>{
306
- return `/guilds/${guildId}/invites`;
307
- },
308
- leave: (guildId)=>{
309
- return `/users/@me/guilds/${guildId}`;
310
- },
311
- members: {
312
- ban: (guildId, userId)=>{
313
- return `/guilds/${guildId}/bans/${userId}`;
314
- },
315
- bans: (guildId, options)=>{
316
- let url = `/guilds/${guildId}/bans?`;
317
- if (options) {
318
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
319
- if (options.limit) url += `limit=${options.limit}`;
320
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
321
- if (options.after) url += `&after=${options.after}`;
322
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
323
- if (options.before) url += `&before=${options.before}`;
324
- }
325
- return url;
326
- },
327
- bot: (guildId)=>{
328
- return `/guilds/${guildId}/members/@me`;
329
- },
330
- member: (guildId, userId)=>{
331
- return `/guilds/${guildId}/members/${userId}`;
332
- },
333
- members: (guildId, options)=>{
334
- let url = `/guilds/${guildId}/members?`;
335
- if (options !== undefined) {
336
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
337
- if (options.limit) url += `limit=${options.limit}`;
338
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
339
- if (options.after) url += `&after=${options.after}`;
340
- }
341
- return url;
342
- },
343
- search: (guildId, query, options)=>{
344
- let url = `/guilds/${guildId}/members/search?query=${encodeURIComponent(query)}`;
345
- if (options) {
346
- if (options.limit !== undefined) url += `&limit=${options.limit}`;
347
- }
348
- return url;
349
- },
350
- prune: (guildId, options)=>{
351
- let url = `/guilds/${guildId}/prune?`;
352
- if (options) {
353
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
354
- if (options.days) url += `days=${options.days}`;
355
- if (Array.isArray(options.includeRoles)) {
356
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
357
- url += `&include_roles=${options.includeRoles.join(',')}`;
358
- } else if (options.includeRoles) {
359
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
360
- url += `&include_roles=${options.includeRoles}`;
361
- }
362
- }
363
- return url;
364
- }
365
- },
366
- mfa: (guildId)=>`/guilds/${guildId}/mfa`,
367
- preview: (guildId)=>{
368
- return `/guilds/${guildId}/preview`;
369
- },
370
- prune: (guildId, options)=>{
371
- let url = `/guilds/${guildId}/prune?`;
372
- if (options) {
373
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
374
- if (options.days) url += `days=${options.days}`;
375
- if (Array.isArray(options.includeRoles)) {
376
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
377
- url += `&include_roles=${options.includeRoles.join(',')}`;
378
- } else if (options.includeRoles) {
379
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
380
- url += `&include_roles=${options.includeRoles}`;
381
- }
382
- }
383
- return url;
384
- },
385
- roles: {
386
- one: (guildId, roleId)=>{
387
- return `/guilds/${guildId}/roles/${roleId}`;
388
- },
389
- all: (guildId)=>{
390
- return `/guilds/${guildId}/roles`;
391
- },
392
- member: (guildId, memberId, roleId)=>{
393
- return `/guilds/${guildId}/members/${memberId}/roles/${roleId}`;
394
- }
395
- },
396
- stickers: (guildId)=>{
397
- return `/guilds/${guildId}/stickers`;
398
- },
399
- sticker: (guildId, stickerId)=>{
400
- return `/guilds/${guildId}/stickers/${stickerId}`;
401
- },
402
- voice: (guildId, userId)=>{
403
- return `/guilds/${guildId}/voice-states/${userId ?? '@me'}`;
404
- },
405
- templates: {
406
- code: (code)=>{
407
- return `/guilds/templates/${code}`;
408
- },
409
- guild: (guildId, code)=>{
410
- return `/guilds/${guildId}/templates/${code}`;
411
- },
412
- all: (guildId)=>{
413
- return `/guilds/${guildId}/templates`;
414
- }
415
- },
416
- vanity: (guildId)=>{
417
- return `/guilds/${guildId}/vanity-url`;
418
- },
419
- regions: (guildId)=>{
420
- return `/guilds/${guildId}/regions`;
421
- },
422
- webhooks: (guildId)=>{
423
- return `/guilds/${guildId}/webhooks`;
424
- },
425
- welcome: (guildId)=>{
426
- return `/guilds/${guildId}/welcome-screen`;
427
- },
428
- widget: (guildId)=>{
429
- return `/guilds/${guildId}/widget`;
430
- },
431
- widgetJson: (guildId)=>{
432
- return `/guilds/${guildId}/widget.json`;
433
- }
434
- },
435
- sticker: (stickerId)=>{
436
- return `/stickers/${stickerId}`;
437
- },
438
- regions: ()=>{
439
- return '/voice/regions';
440
- },
441
- // Interaction Endpoints
442
- interactions: {
443
- commands: {
444
- // Application Endpoints
445
- commands: (applicationId)=>{
446
- return `/applications/${applicationId}/commands`;
447
- },
448
- guilds: {
449
- all (applicationId, guildId) {
450
- return `/applications/${applicationId}/guilds/${guildId}/commands`;
451
- },
452
- one (applicationId, guildId, commandId, withLocalizations) {
453
- let url = `/applications/${applicationId}/guilds/${guildId}/commands/${commandId}?`;
454
- if (withLocalizations !== undefined) {
455
- url += `with_localizations=${withLocalizations.toString()}`;
456
- }
457
- return url;
458
- }
459
- },
460
- permissions: (applicationId, guildId)=>{
461
- return `/applications/${applicationId}/guilds/${guildId}/commands/permissions`;
462
- },
463
- permission: (applicationId, guildId, commandId)=>{
464
- return `/applications/${applicationId}/guilds/${guildId}/commands/${commandId}/permissions`;
465
- },
466
- command: (applicationId, commandId, withLocalizations)=>{
467
- let url = `/applications/${applicationId}/commands/${commandId}?`;
468
- if (withLocalizations !== undefined) {
469
- url += `withLocalizations=${withLocalizations.toString()}`;
470
- }
471
- return url;
472
- }
473
- },
474
- responses: {
475
- // Interaction Endpoints
476
- callback: (interactionId, token)=>{
477
- return `/interactions/${interactionId}/${token}/callback`;
478
- },
479
- original: (interactionId, token)=>{
480
- return `/webhooks/${interactionId}/${token}/messages/@original`;
481
- },
482
- message: (applicationId, token, messageId)=>{
483
- return `/webhooks/${applicationId}/${token}/messages/${messageId}`;
484
- }
485
- }
486
- },
487
- // User endpoints
488
- user (userId) {
489
- return `/users/${userId}`;
490
- },
491
- userBot () {
492
- return '/users/@me';
493
- },
494
- oauth2Application () {
495
- return 'oauth2/applications/@me';
496
- },
497
- gatewayBot () {
498
- return '/gateway/bot';
499
- },
500
- nitroStickerPacks () {
501
- return '/sticker-packs';
502
- }
503
- },
35
+ token: options.token,
36
+ version: options.version ?? DISCORD_API_VERSION,
37
+ routes: createRoutes(),
504
38
  checkRateLimits (url) {
505
39
  const ratelimited = rest.rateLimitedPaths.get(url);
506
40
  const global = rest.rateLimitedPaths.get('global');
@@ -526,11 +60,11 @@ export function createRestManager(options) {
526
60
  'permissions',
527
61
  'allow',
528
62
  'deny'
529
- ].includes(key)) {
63
+ ].includes(key) && obj[key] !== undefined) {
530
64
  newObj[key] = calculateBits(obj[key]);
531
65
  continue;
532
66
  }
533
- if (key === 'defaultMemberPermissions') {
67
+ if (key === 'defaultMemberPermissions' && obj[key] !== undefined) {
534
68
  newObj.default_member_permissions = calculateBits(obj[key]);
535
69
  continue;
536
70
  }
@@ -541,56 +75,47 @@ export function createRestManager(options) {
541
75
  if (typeof obj === 'bigint') return obj.toString();
542
76
  return obj;
543
77
  },
544
- createRequest (options) {
78
+ createRequestBody (method, options) {
545
79
  const headers = {
546
80
  'user-agent': `DiscordBot (https://github.com/discordeno/discordeno, v${version})`
547
81
  };
548
- if (!options.unauthorized) headers.authorization = `Bot ${rest.token}`;
549
- // SOMETIMES SPECIAL HEADERS (E.G. CUSTOM AUTHORIZATION) NEED TO BE USED
550
- if (options.headers) {
551
- for(const key in options.headers){
552
- headers[key.toLowerCase()] = options.headers[key];
553
- }
554
- }
555
- // GET METHODS SHOULD NOT HAVE A BODY
556
- if (options.method === 'GET') {
557
- options.body = undefined;
558
- }
82
+ if (options?.unauthorized !== false) headers.authorization = `Bot ${rest.token}`;
559
83
  // IF A REASON IS PROVIDED ENCODE IT IN HEADERS
560
- if (options.body?.reason) {
561
- headers['X-Audit-Log-Reason'] = encodeURIComponent(options.body.reason);
562
- options.body.reason = undefined;
84
+ if (options?.reason !== undefined) {
85
+ headers[AUDIT_LOG_REASON_HEADER] = encodeURIComponent(options?.reason);
563
86
  }
564
- if (options.body) {
565
- const { file } = options.body;
566
- if (file) {
567
- const files = findFiles(file);
568
- const form = new FormData();
569
- // WHEN CREATING A STICKER, DISCORD WANTS FORM DATA ONLY
570
- if (options.url?.endsWith('/stickers') && options.method === 'POST') {
571
- form.append('file', files[0].blob, files[0].name);
572
- form.append('name', options.body.name);
573
- form.append('description', options.body.description);
574
- form.append('tags', options.body.tags);
575
- } else {
576
- for(let i = 0; i < files.length; i++){
577
- form.append(`file${i}`, files[i].blob, files[i].name);
578
- }
579
- if (file) options.body.file = undefined;
580
- form.append('payload_json', JSON.stringify(rest.changeToDiscordFormat(options.body)));
581
- }
582
- options.body.file = form;
583
- } else if (options.body && ![
584
- 'GET',
585
- 'DELETE'
586
- ].includes(options.method)) {
587
- headers['Content-Type'] = 'application/json';
87
+ let body;
88
+ // TODO: check if we need to add specific check for GET method
89
+ // Since GET does not allow bodies
90
+ // Have to check for attachments first, since body then has to be send in a different way.
91
+ if (options?.files !== undefined) {
92
+ const form = new FormData();
93
+ for(let i = 0; i < options.files.length; ++i){
94
+ form.append(`file${i}`, options.files[i].blob, options.files[i].name);
95
+ }
96
+ form.append('payload_json', JSON.stringify({
97
+ ...options.body,
98
+ files: undefined
99
+ }));
100
+ body = form;
101
+ // No need to set the `content-type` header since `fetch` does that automatically for us when we use a `FormData` object.
102
+ } else if (options?.body !== undefined) {
103
+ if (options.body instanceof FormData) {
104
+ body = options.body;
105
+ // No need to set the `content-type` header since `fetch` does that automatically for us when we use a `FormData` object.
106
+ } else {
107
+ body = JSON.stringify(rest.changeToDiscordFormat(options.body));
108
+ headers['content-type'] = `application/json`;
588
109
  }
589
110
  }
111
+ // SOMETIMES SPECIAL HEADERS (E.G. CUSTOM AUTHORIZATION) NEED TO BE USED
112
+ if (options?.headers) {
113
+ Object.assign(headers, options.headers);
114
+ }
590
115
  return {
116
+ body,
591
117
  headers,
592
- body: options.body?.file ?? JSON.stringify(rest.changeToDiscordFormat(options.body)),
593
- method: options.method
118
+ method
594
119
  };
595
120
  },
596
121
  processRateLimitedPaths () {
@@ -623,13 +148,13 @@ export function createRestManager(options) {
623
148
  /** Processes the rate limit headers and determines if it needs to be rate limited and returns the bucket id if available */ processHeaders (url, headers) {
624
149
  let rateLimited = false;
625
150
  // GET ALL NECESSARY HEADERS
626
- const remaining = headers.get('x-ratelimit-remaining');
627
- const retryAfter = headers.get('x-ratelimit-reset-after');
151
+ const remaining = headers.get(RATE_LIMIT_REMAINING_HEADER);
152
+ const retryAfter = headers.get(RATE_LIMIT_RESET_AFTER_HEADER);
628
153
  const reset = Date.now() + Number(retryAfter) * 1000;
629
- const global = headers.get('x-ratelimit-global');
154
+ const global = headers.get(RATE_LIMIT_GLOBAL_HEADER);
630
155
  // undefined override null needed for typings
631
- const bucketId = headers.get('x-ratelimit-bucket') ?? undefined;
632
- const limit = headers.get('x-ratelimit-limit');
156
+ const bucketId = headers.get(RATE_LIMIT_BUCKET_HEADER) ?? undefined;
157
+ const limit = headers.get(RATE_LIMIT_LIMIT_HEADER);
633
158
  rest.queues.get(url)?.handleCompletedRequest({
634
159
  remaining: remaining ? Number(remaining) : undefined,
635
160
  interval: retryAfter ? Number(retryAfter) * 1000 : undefined,
@@ -655,8 +180,8 @@ export function createRestManager(options) {
655
180
  }
656
181
  // IF THERE IS NO REMAINING GLOBAL LIMIT, MARK IT RATE LIMITED GLOBALLY
657
182
  if (global) {
658
- const retryAfter1 = headers.get('retry-after');
659
- const globalReset = Date.now() + Number(retryAfter1) * 1000;
183
+ const retryAfter = headers.get('retry-after');
184
+ const globalReset = Date.now() + Number(retryAfter) * 1000;
660
185
  // rest.debug(
661
186
  // `[REST = Globally Rate Limited] URL: ${url} | Global Rest: ${globalReset}`
662
187
  // )
@@ -684,13 +209,8 @@ export function createRestManager(options) {
684
209
  return rateLimited ? bucketId : undefined;
685
210
  },
686
211
  async sendRequest (options) {
687
- const url = options.url.startsWith('https://') ? options.url : `${rest.baseUrl}/v${rest.version}${options.url}`;
688
- const payload = rest.createRequest({
689
- method: options.method,
690
- url: options.url,
691
- body: options.body,
692
- ...options.options
693
- });
212
+ const url = `${rest.baseUrl}/v${rest.version}${options.route}`;
213
+ const payload = rest.createRequestBody(options.method, options.requestBodyOptions);
694
214
  logger.debug(`sending request to ${url}`, 'with payload:', {
695
215
  ...payload,
696
216
  headers: {
@@ -701,75 +221,73 @@ export function createRestManager(options) {
701
221
  const response = await fetch(url, payload);
702
222
  logger.debug(`request fetched from ${url} with status ${response.status} & ${response.statusText}`);
703
223
  // Set the bucket id if it was available on the headers
704
- const bucketId = rest.processHeaders(rest.simplifyUrl(options.url, options.method), response.headers);
224
+ const bucketId = rest.processHeaders(rest.simplifyUrl(options.route, options.method), response.headers);
705
225
  if (bucketId) options.bucketId = bucketId;
706
226
  if (response.status < 200 || response.status >= 400) {
707
227
  logger.debug(`Request to ${url} failed.`);
708
- if (response.status === 429) {
709
- logger.debug(`Request to ${url} was ratelimited.`);
710
- // Too many attempts, get rid of request from queue.
711
- if (options.retryCount++ >= rest.maxRetryCount) {
712
- logger.debug(`Request to ${url} exceeded the maximum allowed retries.`, 'with payload:', payload);
713
- // rest.debug(`[REST - RetriesMaxed] ${JSON.stringify(options)}`)
714
- // Remove item from queue to prevent retry
715
- return options.reject({
716
- ok: false,
717
- status: response.status,
718
- error: 'The options was rate limited and it maxed out the retries limit.'
719
- });
720
- }
721
- // Rate limited, add back to queue
722
- rest.invalidBucket.handleCompletedRequest(response.status, response.headers.get('X-RateLimit-Scope') === 'shared');
723
- const resetAfter = response.headers.get('x-ratelimit-reset-after');
724
- if (resetAfter) await delay(Number(resetAfter) * 1000);
725
- // process the response to prevent mem leak
726
- await response.json();
727
- return await options.retryRequest?.(options);
228
+ if (response.status !== 429) {
229
+ options.reject({
230
+ ok: false,
231
+ status: response.status,
232
+ body: await response.text()
233
+ });
234
+ return;
728
235
  }
729
- return options.reject({
730
- ok: false,
731
- status: response.status,
732
- body: JSON.stringify(await response.json())
733
- });
236
+ logger.debug(`Request to ${url} was ratelimited.`);
237
+ // Too many attempts, get rid of request from queue.
238
+ if (options.retryCount >= rest.maxRetryCount) {
239
+ logger.debug(`Request to ${url} exceeded the maximum allowed retries.`, 'with payload:', payload);
240
+ // rest.debug(`[REST - RetriesMaxed] ${JSON.stringify(options)}`)
241
+ options.reject({
242
+ ok: false,
243
+ status: response.status,
244
+ error: 'The request was rate limited and it maxed out the retries limit.'
245
+ });
246
+ return;
247
+ }
248
+ options.retryCount += 1;
249
+ // Rate limited, add back to queue
250
+ rest.invalidBucket.handleCompletedRequest(response.status, response.headers.get(RATE_LIMIT_SCOPE_HEADER) === 'shared');
251
+ const resetAfter = response.headers.get(RATE_LIMIT_RESET_AFTER_HEADER);
252
+ if (resetAfter) await delay(Number(resetAfter) * 1000);
253
+ // process the response to prevent mem leak
254
+ await response.arrayBuffer();
255
+ return await options.retryRequest?.(options);
734
256
  }
735
- const is204 = response.status === 204;
736
- const json = is204 ? undefined : await response.json();
737
- // Discord sometimes sends no response with 204 code
738
- return options.resolve({
257
+ // Discord sometimes sends no response with no content.
258
+ options.resolve({
739
259
  ok: true,
740
260
  status: response.status,
741
- body: JSON.stringify(json)
261
+ body: response.status === 204 ? undefined : await response.text()
742
262
  });
743
263
  },
744
- // Credits: github.com/abalabahaha/eris lib/rest/RequestHandler.js#L397
745
- // Modified for our use-case
746
264
  simplifyUrl (url, method) {
747
- let route = url.replace(/\/([a-z-]+)\/(?:[0-9]{17,19})/g, function(match, p) {
748
- return [
749
- 'channels',
750
- 'guilds'
751
- ].includes(p) ? match : `/${p}/x`;
752
- }).replace(/\/reactions\/[^/]+/g, '/reactions/x');
753
- // GENERAL /reactions and /reactions/emoji/@me share the buckets
754
- if (route.includes('/reactions')) {
755
- route = route.substring(0, route.indexOf('/reactions') + '/reactions'.length);
265
+ const parts = url.split('/');
266
+ const secondLastPart = parts[parts.length - 2];
267
+ if (secondLastPart === 'channels' || secondLastPart === 'guilds') {
268
+ return url;
756
269
  }
757
- // Delete Message endpoint has its own rate limit
758
- if (method === 'DELETE' && route.endsWith('/messages/x')) {
759
- route = method + route;
270
+ if (secondLastPart === 'reactions' || parts[parts.length - 1] === '@me') {
271
+ parts.splice(-2);
272
+ parts.push('reactions');
273
+ } else {
274
+ parts.splice(-1);
275
+ parts.push('x');
276
+ }
277
+ if (parts[parts.length - 3] === 'reactions') {
278
+ parts.splice(-2);
279
+ }
280
+ if (method === 'DELETE' && secondLastPart === 'messages') {
281
+ return `D${parts.join('/')}`;
282
+ }
283
+ return parts.join('/');
284
+ },
285
+ async processRequest (request) {
286
+ const url = rest.simplifyUrl(request.route, request.method);
287
+ if (request.runThroughQueue === false) {
288
+ await rest.sendRequest(request);
289
+ return;
760
290
  }
761
- return route;
762
- },
763
- processRequest (request) {
764
- const route = request.url.substring(request.url.indexOf('api/'));
765
- const parts = route.split('/');
766
- // Remove the api/
767
- parts.shift();
768
- // Removes the /v#/
769
- if (parts[0]?.startsWith('v')) parts.shift();
770
- // Set the full url to discord api in case it was recieved in a proxy rest
771
- request.url = `${rest.baseUrl}/v${rest.version}/${parts.join('/')}`;
772
- const url = rest.simplifyUrl(request.url, request.method);
773
291
  const queue = rest.queues.get(url);
774
292
  if (queue !== undefined) {
775
293
  queue.makeRequest(request);
@@ -785,45 +303,65 @@ export function createRestManager(options) {
785
303
  rest.queues.set(url, bucketQueue);
786
304
  }
787
305
  },
788
- async makeRequest (method, url, body, options) {
789
- return await new Promise((resolve, reject)=>{
306
+ async makeRequest (method, route, options) {
307
+ if (rest.isProxied) {
308
+ if (rest.authorization !== undefined) {
309
+ options ??= {};
310
+ options.headers ??= {};
311
+ options.headers.authorization = rest.authorization;
312
+ }
313
+ const result = await fetch(`${rest.baseUrl}/v${rest.version}${route}`, rest.createRequestBody(method, options));
314
+ if (!result.ok) {
315
+ const err = await result.json().catch(()=>{});
316
+ // Legacy Handling to not break old code or when body is missing
317
+ if (!err?.body) throw new Error(`Error: ${err.message ?? result.statusText}`);
318
+ throw new Error(JSON.stringify(err));
319
+ }
320
+ return result.status !== 204 ? await result.json() : undefined;
321
+ }
322
+ // eslint-disable-next-line no-async-promise-executor
323
+ return await new Promise(async (resolve, reject)=>{
790
324
  const payload = {
791
- url,
325
+ route,
792
326
  method,
793
- body,
327
+ requestBodyOptions: options,
794
328
  retryCount: 0,
795
- retryRequest: async function(options) {
796
- rest.processRequest(payload);
329
+ retryRequest: async function(payload) {
330
+ await rest.processRequest(payload);
331
+ },
332
+ resolve: (data)=>{
333
+ resolve(data.status !== 204 ? JSON.parse(data.body ?? '{}') : undefined);
797
334
  },
798
- resolve: (data)=>resolve(data.status !== 204 ? JSON.parse(data.body ?? '{}') : undefined),
799
335
  reject,
800
- options
336
+ runThroughQueue: options?.runThroughQueue
801
337
  };
802
- rest.processRequest(payload);
338
+ await rest.processRequest(payload);
803
339
  });
804
340
  },
805
- async get (url) {
806
- return camelize(await rest.makeRequest('GET', url));
341
+ async get (url, options) {
342
+ return camelize(await rest.makeRequest('GET', url, options));
807
343
  },
808
- async post (url, body) {
809
- return camelize(await rest.makeRequest('POST', url, body));
344
+ async post (url, options) {
345
+ return camelize(await rest.makeRequest('POST', url, options));
810
346
  },
811
- async delete (url, body) {
812
- return camelize(await rest.makeRequest('DELETE', url, body));
347
+ async delete (url, options) {
348
+ camelize(await rest.makeRequest('DELETE', url, options));
813
349
  },
814
- async patch (url, body) {
815
- return camelize(await rest.makeRequest('PATCH', url, body));
350
+ async patch (url, options) {
351
+ return camelize(await rest.makeRequest('PATCH', url, options));
816
352
  },
817
- async put (url, body, options) {
818
- return camelize(await rest.makeRequest('PUT', url, body, options));
353
+ async put (url, options) {
354
+ return camelize(await rest.makeRequest('PUT', url, options));
819
355
  },
820
356
  async addReaction (channelId, messageId, reaction) {
821
357
  reaction = processReactionString(reaction);
822
- return await rest.put(rest.routes.channels.reactions.bot(channelId, messageId, reaction));
358
+ await rest.put(rest.routes.channels.reactions.bot(channelId, messageId, reaction));
823
359
  },
824
360
  async addReactions (channelId, messageId, reactions, ordered = false) {
825
361
  if (!ordered) {
826
- await Promise.all(reactions.map(async (reaction)=>await rest.addReaction(channelId, messageId, reaction)));
362
+ await Promise.all(reactions.map(async (reaction)=>{
363
+ await rest.addReaction(channelId, messageId, reaction);
364
+ }));
827
365
  return;
828
366
  }
829
367
  for (const reaction of reactions){
@@ -831,283 +369,408 @@ export function createRestManager(options) {
831
369
  }
832
370
  },
833
371
  async addRole (guildId, userId, roleId, reason) {
834
- return await rest.put(rest.routes.guilds.roles.member(guildId, userId, roleId), {
372
+ await rest.put(rest.routes.guilds.roles.member(guildId, userId, roleId), {
835
373
  reason
836
374
  });
837
375
  },
838
376
  async addThreadMember (channelId, userId) {
839
- return await rest.put(rest.routes.channels.threads.user(channelId, userId));
377
+ await rest.put(rest.routes.channels.threads.user(channelId, userId));
840
378
  },
841
- async createAutomodRule (guildId, options) {
842
- return await rest.post(rest.routes.guilds.automod.rules(guildId), options);
379
+ async createAutomodRule (guildId, body, reason) {
380
+ return await rest.post(rest.routes.guilds.automod.rules(guildId), {
381
+ body,
382
+ reason
383
+ });
843
384
  },
844
- async createChannel (guildId, options) {
845
- return await rest.post(rest.routes.guilds.channels(guildId), options);
385
+ async createChannel (guildId, body, reason) {
386
+ return await rest.post(rest.routes.guilds.channels(guildId), {
387
+ body,
388
+ reason
389
+ });
846
390
  },
847
- async createEmoji (guildId, options) {
848
- return await rest.post(rest.routes.guilds.emojis(guildId), options);
391
+ async createEmoji (guildId, body, reason) {
392
+ return await rest.post(rest.routes.guilds.emojis(guildId), {
393
+ body,
394
+ reason
395
+ });
849
396
  },
850
- async createGlobalApplicationCommand (command) {
851
- return await rest.post(rest.routes.interactions.commands.commands(rest.applicationId), command);
397
+ async createGlobalApplicationCommand (body) {
398
+ return await rest.post(rest.routes.interactions.commands.commands(rest.applicationId), {
399
+ body
400
+ });
852
401
  },
853
- async createGuild (options) {
854
- return await rest.post(rest.routes.guilds.all(), options);
402
+ async createGuild (body) {
403
+ return await rest.post(rest.routes.guilds.all(), {
404
+ body
405
+ });
855
406
  },
856
- async createGuildApplicationCommand (command, guildId) {
857
- return await rest.post(rest.routes.interactions.commands.guilds.all(rest.applicationId, guildId), command);
407
+ async createGuildApplicationCommand (body, guildId) {
408
+ return await rest.post(rest.routes.interactions.commands.guilds.all(rest.applicationId, guildId), {
409
+ body
410
+ });
858
411
  },
859
- async createGuildFromTemplate (templateCode, options) {
860
- if (options.icon) {
861
- options.icon = await urlToBase64(options.icon);
412
+ async createGuildFromTemplate (templateCode, body) {
413
+ if (body.icon) {
414
+ body.icon = await urlToBase64(body.icon);
862
415
  }
863
- return await rest.post(rest.routes.guilds.templates.code(templateCode), options);
416
+ return await rest.post(rest.routes.guilds.templates.code(templateCode), {
417
+ body
418
+ });
864
419
  },
865
- async createGuildSticker (guildId, options) {
866
- return await rest.post(rest.routes.guilds.stickers(guildId), options);
420
+ async createGuildSticker (guildId, options, reason) {
421
+ const form = new FormData();
422
+ form.append('file', options.file.blob, options.file.name);
423
+ form.append('name', options.name);
424
+ form.append('description', options.description);
425
+ form.append('tags', options.tags);
426
+ return await rest.post(rest.routes.guilds.stickers(guildId), {
427
+ body: form,
428
+ reason
429
+ });
867
430
  },
868
- async createGuildTemplate (guildId, options) {
869
- return await rest.post(rest.routes.guilds.templates.all(guildId), options);
431
+ async createGuildTemplate (guildId, body) {
432
+ return await rest.post(rest.routes.guilds.templates.all(guildId), {
433
+ body
434
+ });
870
435
  },
871
- async createForumThread (channelId, options) {
872
- return await rest.post(rest.routes.channels.forum(channelId), options);
436
+ async createForumThread (channelId, body, reason) {
437
+ return await rest.post(rest.routes.channels.forum(channelId), {
438
+ body,
439
+ files: body.files,
440
+ reason
441
+ });
873
442
  },
874
- async createInvite (channelId, options = {}) {
875
- return await rest.post(rest.routes.channels.invites(channelId), options);
443
+ async createInvite (channelId, body = {}, reason) {
444
+ return await rest.post(rest.routes.channels.invites(channelId), {
445
+ body,
446
+ reason
447
+ });
876
448
  },
877
- async createRole (guildId, options, reason) {
449
+ async createRole (guildId, body, reason) {
878
450
  return await rest.post(rest.routes.guilds.roles.all(guildId), {
879
- ...options,
451
+ body,
880
452
  reason
881
453
  });
882
454
  },
883
- async createScheduledEvent (guildId, options) {
884
- return await rest.post(rest.routes.guilds.events.events(guildId), options);
455
+ async createScheduledEvent (guildId, body, reason) {
456
+ return await rest.post(rest.routes.guilds.events.events(guildId), {
457
+ body,
458
+ reason
459
+ });
885
460
  },
886
- async createStageInstance (options) {
887
- return await rest.post(rest.routes.channels.stages(), options);
461
+ async createStageInstance (body, reason) {
462
+ return await rest.post(rest.routes.channels.stages(), {
463
+ body,
464
+ reason
465
+ });
888
466
  },
889
- async createWebhook (channelId, options) {
467
+ async createWebhook (channelId, options, reason) {
890
468
  return await rest.post(rest.routes.channels.webhooks(channelId), {
891
- name: options.name,
892
- avatar: options.avatar ? await urlToBase64(options.avatar) : undefined,
893
- reason: options.reason
469
+ body: {
470
+ name: options.name,
471
+ avatar: options.avatar ? await urlToBase64(options.avatar) : undefined
472
+ },
473
+ reason
894
474
  });
895
475
  },
896
476
  async deleteAutomodRule (guildId, ruleId, reason) {
897
- return await rest.delete(rest.routes.guilds.automod.rule(guildId, ruleId), {
477
+ await rest.delete(rest.routes.guilds.automod.rule(guildId, ruleId), {
898
478
  reason
899
479
  });
900
480
  },
901
481
  async deleteChannel (channelId, reason) {
902
- return await rest.delete(rest.routes.channels.channel(channelId), {
482
+ await rest.delete(rest.routes.channels.channel(channelId), {
903
483
  reason
904
484
  });
905
485
  },
906
486
  async deleteChannelPermissionOverride (channelId, overwriteId, reason) {
907
- return await rest.delete(rest.routes.channels.overwrite(channelId, overwriteId), reason ? {
487
+ await rest.delete(rest.routes.channels.overwrite(channelId, overwriteId), {
908
488
  reason
909
- } : undefined);
489
+ });
910
490
  },
911
491
  async deleteEmoji (guildId, id, reason) {
912
- return await rest.delete(rest.routes.guilds.emoji(guildId, id), {
492
+ await rest.delete(rest.routes.guilds.emoji(guildId, id), {
913
493
  reason
914
494
  });
915
495
  },
916
496
  async deleteFollowupMessage (token, messageId) {
917
- return await rest.delete(rest.routes.interactions.responses.message(rest.applicationId, token, messageId));
497
+ await rest.delete(rest.routes.interactions.responses.message(rest.applicationId, token, messageId), {
498
+ unauthorized: true
499
+ });
918
500
  },
919
501
  async deleteGlobalApplicationCommand (commandId) {
920
- return await rest.delete(rest.routes.interactions.commands.command(rest.applicationId, commandId));
502
+ await rest.delete(rest.routes.interactions.commands.command(rest.applicationId, commandId));
921
503
  },
922
504
  async deleteGuild (guildId) {
923
- return await rest.delete(rest.routes.guilds.guild(guildId));
505
+ await rest.delete(rest.routes.guilds.guild(guildId));
924
506
  },
925
507
  async deleteGuildApplicationCommand (commandId, guildId) {
926
- return await rest.delete(rest.routes.interactions.commands.guilds.one(rest.applicationId, guildId, commandId));
508
+ await rest.delete(rest.routes.interactions.commands.guilds.one(rest.applicationId, guildId, commandId));
927
509
  },
928
510
  async deleteGuildSticker (guildId, stickerId, reason) {
929
- return await rest.delete(rest.routes.guilds.sticker(guildId, stickerId), reason ? {
511
+ await rest.delete(rest.routes.guilds.sticker(guildId, stickerId), {
930
512
  reason
931
- } : undefined);
513
+ });
932
514
  },
933
515
  async deleteGuildTemplate (guildId, templateCode) {
934
- return await rest.delete(rest.routes.guilds.templates.guild(guildId, templateCode));
516
+ await rest.delete(rest.routes.guilds.templates.guild(guildId, templateCode));
935
517
  },
936
- async deleteIntegration (guildId, integrationId) {
937
- return await rest.delete(rest.routes.guilds.integration(guildId, integrationId));
518
+ async deleteIntegration (guildId, integrationId, reason) {
519
+ await rest.delete(rest.routes.guilds.integration(guildId, integrationId), {
520
+ reason
521
+ });
938
522
  },
939
523
  async deleteInvite (inviteCode, reason) {
940
- return await rest.delete(rest.routes.guilds.invite(inviteCode), reason ? {
524
+ await rest.delete(rest.routes.guilds.invite(inviteCode), {
941
525
  reason
942
- } : undefined);
526
+ });
943
527
  },
944
528
  async deleteMessage (channelId, messageId, reason) {
945
- return await rest.delete(rest.routes.channels.message(channelId, messageId), {
529
+ await rest.delete(rest.routes.channels.message(channelId, messageId), {
946
530
  reason
947
531
  });
948
532
  },
949
533
  async deleteMessages (channelId, messageIds, reason) {
950
- return await rest.post(rest.routes.channels.bulk(channelId), {
951
- messages: messageIds.slice(0, 100).map((id)=>id.toString()),
534
+ await rest.post(rest.routes.channels.bulk(channelId), {
535
+ body: {
536
+ messages: messageIds.slice(0, 100).map((id)=>id.toString())
537
+ },
952
538
  reason
953
539
  });
954
540
  },
955
541
  async deleteOriginalInteractionResponse (token) {
956
- return await rest.delete(rest.routes.interactions.responses.original(rest.applicationId, token));
542
+ await rest.delete(rest.routes.interactions.responses.original(rest.applicationId, token), {
543
+ unauthorized: true
544
+ });
957
545
  },
958
546
  async deleteOwnReaction (channelId, messageId, reaction) {
959
547
  reaction = processReactionString(reaction);
960
- return await rest.delete(rest.routes.channels.reactions.bot(channelId, messageId, reaction));
548
+ await rest.delete(rest.routes.channels.reactions.bot(channelId, messageId, reaction));
961
549
  },
962
550
  async deleteReactionsAll (channelId, messageId) {
963
- return await rest.delete(rest.routes.channels.reactions.all(channelId, messageId));
551
+ await rest.delete(rest.routes.channels.reactions.all(channelId, messageId));
964
552
  },
965
553
  async deleteReactionsEmoji (channelId, messageId, reaction) {
966
554
  reaction = processReactionString(reaction);
967
- return await rest.delete(rest.routes.channels.reactions.emoji(channelId, messageId, reaction));
555
+ await rest.delete(rest.routes.channels.reactions.emoji(channelId, messageId, reaction));
968
556
  },
969
- async deleteRole (guildId, roleId) {
970
- return await rest.delete(rest.routes.guilds.roles.one(guildId, roleId));
557
+ async deleteRole (guildId, roleId, reason) {
558
+ await rest.delete(rest.routes.guilds.roles.one(guildId, roleId), {
559
+ reason
560
+ });
971
561
  },
972
562
  async deleteScheduledEvent (guildId, eventId) {
973
- return await rest.delete(rest.routes.guilds.events.event(guildId, eventId));
563
+ await rest.delete(rest.routes.guilds.events.event(guildId, eventId));
974
564
  },
975
565
  async deleteStageInstance (channelId, reason) {
976
- return await rest.delete(rest.routes.channels.stage(channelId), reason ? {
566
+ await rest.delete(rest.routes.channels.stage(channelId), {
977
567
  reason
978
- } : undefined);
568
+ });
979
569
  },
980
570
  async deleteUserReaction (channelId, messageId, userId, reaction) {
981
571
  reaction = processReactionString(reaction);
982
- return await rest.delete(rest.routes.channels.reactions.user(channelId, messageId, reaction, userId));
572
+ await rest.delete(rest.routes.channels.reactions.user(channelId, messageId, reaction, userId));
983
573
  },
984
574
  async deleteWebhook (webhookId, reason) {
985
- return await rest.delete(rest.routes.webhooks.id(webhookId), {
575
+ await rest.delete(rest.routes.webhooks.id(webhookId), {
986
576
  reason
987
577
  });
988
578
  },
989
579
  async deleteWebhookMessage (webhookId, token, messageId, options) {
990
- return await rest.delete(rest.routes.webhooks.message(webhookId, token, messageId, options));
580
+ await rest.delete(rest.routes.webhooks.message(webhookId, token, messageId, options));
991
581
  },
992
582
  async deleteWebhookWithToken (webhookId, token) {
993
- return await rest.delete(rest.routes.webhooks.webhook(webhookId, token));
583
+ await rest.delete(rest.routes.webhooks.webhook(webhookId, token));
994
584
  },
995
- async editApplicationCommandPermissions (guildId, commandId, bearerToken, options) {
585
+ async editApplicationCommandPermissions (guildId, commandId, bearerToken, permissions) {
996
586
  return await rest.put(rest.routes.interactions.commands.permission(rest.applicationId, guildId, commandId), {
997
- permissions: options
998
- }, {
587
+ body: {
588
+ permissions
589
+ },
999
590
  headers: {
1000
591
  authorization: `Bearer ${bearerToken}`
1001
592
  }
1002
593
  });
1003
594
  },
1004
- async editAutomodRule (guildId, ruleId, options) {
1005
- return await rest.patch(rest.routes.guilds.automod.rule(guildId, ruleId), options);
595
+ async editAutomodRule (guildId, ruleId, body, reason) {
596
+ return await rest.patch(rest.routes.guilds.automod.rule(guildId, ruleId), {
597
+ body,
598
+ reason
599
+ });
1006
600
  },
1007
601
  async editBotProfile (options) {
1008
602
  const avatar = options?.botAvatarURL ? await urlToBase64(options?.botAvatarURL) : options?.botAvatarURL;
1009
603
  return await rest.patch(rest.routes.userBot(), {
1010
- username: options.username?.trim(),
1011
- avatar
604
+ body: {
605
+ username: options.username?.trim(),
606
+ avatar
607
+ }
1012
608
  });
1013
609
  },
1014
- async editChannel (channelId, options) {
1015
- return await rest.patch(rest.routes.channels.channel(channelId), options);
610
+ async editChannel (channelId, body, reason) {
611
+ return await rest.patch(rest.routes.channels.channel(channelId), {
612
+ body,
613
+ reason
614
+ });
1016
615
  },
1017
- async editChannelPermissionOverrides (channelId, options) {
1018
- return await rest.put(rest.routes.channels.overwrite(channelId, options.id), options);
616
+ async editChannelPermissionOverrides (channelId, body, reason) {
617
+ await rest.put(rest.routes.channels.overwrite(channelId, body.id), {
618
+ body,
619
+ reason
620
+ });
1019
621
  },
1020
- async editChannelPositions (guildId, channelPositions) {
1021
- return await rest.patch(rest.routes.guilds.channels(guildId), channelPositions);
622
+ async editChannelPositions (guildId, body) {
623
+ await rest.patch(rest.routes.guilds.channels(guildId), {
624
+ body
625
+ });
1022
626
  },
1023
- async editEmoji (guildId, id, options) {
1024
- return await rest.patch(rest.routes.guilds.emoji(guildId, id), options);
627
+ async editEmoji (guildId, id, body, reason) {
628
+ return await rest.patch(rest.routes.guilds.emoji(guildId, id), {
629
+ body,
630
+ reason
631
+ });
1025
632
  },
1026
- async editFollowupMessage (token, messageId, options) {
1027
- return await rest.patch(rest.routes.interactions.responses.message(rest.applicationId, token, messageId), options);
633
+ async editFollowupMessage (token, messageId, body) {
634
+ return await rest.patch(rest.routes.interactions.responses.message(rest.applicationId, token, messageId), {
635
+ body,
636
+ files: body.files,
637
+ unauthorized: true
638
+ });
1028
639
  },
1029
- async editGlobalApplicationCommand (commandId, options) {
1030
- return await rest.patch(rest.routes.interactions.commands.command(rest.applicationId, commandId), options);
640
+ async editGlobalApplicationCommand (commandId, body) {
641
+ return await rest.patch(rest.routes.interactions.commands.command(rest.applicationId, commandId), {
642
+ body
643
+ });
1031
644
  },
1032
- async editGuild (guildId, options) {
1033
- return await rest.patch(rest.routes.guilds.guild(guildId), options);
645
+ async editGuild (guildId, body, reason) {
646
+ return await rest.patch(rest.routes.guilds.guild(guildId), {
647
+ body,
648
+ reason
649
+ });
1034
650
  },
1035
- async editGuildApplicationCommand (commandId, guildId, options) {
1036
- return await rest.patch(rest.routes.interactions.commands.guilds.one(rest.applicationId, guildId, commandId), options);
651
+ async editGuildApplicationCommand (commandId, guildId, body) {
652
+ return await rest.patch(rest.routes.interactions.commands.guilds.one(rest.applicationId, guildId, commandId), {
653
+ body
654
+ });
1037
655
  },
1038
656
  async editGuildMfaLevel (guildId, mfaLevel, reason) {
1039
- return await rest.post(rest.routes.guilds.mfa(guildId), {
1040
- level: mfaLevel,
657
+ await rest.post(rest.routes.guilds.mfa(guildId), {
658
+ body: {
659
+ level: mfaLevel
660
+ },
1041
661
  reason
1042
662
  });
1043
663
  },
1044
- async editGuildSticker (guildId, stickerId, options) {
1045
- return await rest.patch(rest.routes.guilds.sticker(guildId, stickerId), options);
664
+ async editGuildSticker (guildId, stickerId, body, reason) {
665
+ return await rest.patch(rest.routes.guilds.sticker(guildId, stickerId), {
666
+ body,
667
+ reason
668
+ });
1046
669
  },
1047
- async editGuildTemplate (guildId, templateCode, options) {
1048
- return await rest.patch(rest.routes.guilds.templates.guild(guildId, templateCode), options);
670
+ async editGuildTemplate (guildId, templateCode, body) {
671
+ return await rest.patch(rest.routes.guilds.templates.guild(guildId, templateCode), {
672
+ body
673
+ });
1049
674
  },
1050
- async editMessage (channelId, messageId, options) {
1051
- return await rest.patch(rest.routes.channels.message(channelId, messageId), options);
675
+ async editMessage (channelId, messageId, body) {
676
+ return await rest.patch(rest.routes.channels.message(channelId, messageId), {
677
+ body
678
+ });
1052
679
  },
1053
- async editOriginalInteractionResponse (token, options) {
1054
- return await rest.patch(rest.routes.interactions.responses.original(rest.applicationId, token), options);
680
+ async editOriginalInteractionResponse (token, body) {
681
+ return await rest.patch(rest.routes.interactions.responses.original(rest.applicationId, token), {
682
+ body,
683
+ files: body.files
684
+ });
1055
685
  },
1056
686
  async editOriginalWebhookMessage (webhookId, token, options) {
1057
687
  return await rest.patch(rest.routes.webhooks.original(webhookId, token, options), {
1058
- type: InteractionResponseTypes.UpdateMessage,
1059
- data: options
688
+ body: {
689
+ type: InteractionResponseTypes.UpdateMessage,
690
+ data: options
691
+ },
692
+ files: options.files,
693
+ unauthorized: true
1060
694
  });
1061
695
  },
1062
696
  async editOwnVoiceState (guildId, options) {
1063
- return await rest.patch(rest.routes.guilds.voice(guildId), {
1064
- channel_id: options.channelId,
1065
- suppress: options.suppress,
1066
- request_to_speak_timestamp: options.requestToSpeakTimestamp ? new Date(options.requestToSpeakTimestamp).toISOString() : options.requestToSpeakTimestamp
697
+ await rest.patch(rest.routes.guilds.voice(guildId), {
698
+ body: {
699
+ ...options,
700
+ request_to_speak_timestamp: options.requestToSpeakTimestamp ? new Date(options.requestToSpeakTimestamp).toISOString() : options.requestToSpeakTimestamp
701
+ }
1067
702
  });
1068
703
  },
1069
- async editScheduledEvent (guildId, eventId, options) {
1070
- return await rest.patch(rest.routes.guilds.events.event(guildId, eventId), options);
704
+ async editScheduledEvent (guildId, eventId, body, reason) {
705
+ return await rest.patch(rest.routes.guilds.events.event(guildId, eventId), {
706
+ body,
707
+ reason
708
+ });
1071
709
  },
1072
- async editRole (guildId, roleId, options) {
1073
- return await rest.patch(rest.routes.guilds.roles.one(guildId, roleId), options);
710
+ async editRole (guildId, roleId, body, reason) {
711
+ return await rest.patch(rest.routes.guilds.roles.one(guildId, roleId), {
712
+ body,
713
+ reason
714
+ });
1074
715
  },
1075
- async editRolePositions (guildId, options) {
1076
- return await rest.patch(rest.routes.guilds.roles.all(guildId), options);
716
+ async editRolePositions (guildId, body, reason) {
717
+ return await rest.patch(rest.routes.guilds.roles.all(guildId), {
718
+ body,
719
+ reason
720
+ });
1077
721
  },
1078
- async editStageInstance (channelId, data) {
722
+ async editStageInstance (channelId, topic, reason) {
1079
723
  return await rest.patch(rest.routes.channels.stage(channelId), {
1080
- topic: data.topic
724
+ body: {
725
+ topic
726
+ },
727
+ reason
1081
728
  });
1082
729
  },
1083
730
  async editUserVoiceState (guildId, options) {
1084
- return await rest.patch(rest.routes.guilds.voice(guildId, options.userId), {
1085
- channel_id: options.channelId,
1086
- suppress: options.suppress,
1087
- user_id: options.userId
731
+ await rest.patch(rest.routes.guilds.voice(guildId, options.userId), {
732
+ body: options
1088
733
  });
1089
734
  },
1090
- async editWebhook (webhookId, options) {
1091
- return await rest.patch(rest.routes.webhooks.id(webhookId), options);
735
+ async editWebhook (webhookId, body, reason) {
736
+ return await rest.patch(rest.routes.webhooks.id(webhookId), {
737
+ body,
738
+ reason
739
+ });
1092
740
  },
1093
741
  async editWebhookMessage (webhookId, token, messageId, options) {
1094
- return await rest.patch(rest.routes.webhooks.message(webhookId, token, messageId, options), options);
742
+ return await rest.patch(rest.routes.webhooks.message(webhookId, token, messageId, options), {
743
+ body: options,
744
+ files: options.files
745
+ });
1095
746
  },
1096
- async editWebhookWithToken (webhookId, token, options) {
1097
- return await rest.patch(rest.routes.webhooks.webhook(webhookId, token), options);
747
+ async editWebhookWithToken (webhookId, token, body) {
748
+ return await rest.patch(rest.routes.webhooks.webhook(webhookId, token), {
749
+ body
750
+ });
1098
751
  },
1099
- async editWelcomeScreen (guildId, options) {
1100
- return await rest.patch(rest.routes.guilds.welcome(guildId), options);
752
+ async editWelcomeScreen (guildId, body, reason) {
753
+ return await rest.patch(rest.routes.guilds.welcome(guildId), {
754
+ body,
755
+ reason
756
+ });
1101
757
  },
1102
- async editWidgetSettings (guildId, options) {
1103
- return await rest.patch(rest.routes.guilds.widget(guildId), options);
758
+ async editWidgetSettings (guildId, body, reason) {
759
+ return await rest.patch(rest.routes.guilds.widget(guildId), {
760
+ body,
761
+ reason
762
+ });
1104
763
  },
1105
764
  async executeWebhook (webhookId, token, options) {
1106
- return await rest.post(rest.routes.webhooks.webhook(webhookId, token, options), options);
765
+ return await rest.post(rest.routes.webhooks.webhook(webhookId, token, options), {
766
+ body: options
767
+ });
1107
768
  },
1108
769
  async followAnnouncement (sourceChannelId, targetChannelId) {
1109
770
  return await rest.post(rest.routes.channels.follow(sourceChannelId), {
1110
- webhook_channel_id: targetChannelId
771
+ body: {
772
+ webhook_channel_id: targetChannelId
773
+ }
1111
774
  });
1112
775
  },
1113
776
  async getActiveThreads (guildId) {
@@ -1154,7 +817,9 @@ export function createRestManager(options) {
1154
817
  },
1155
818
  async getDmChannel (userId) {
1156
819
  return await rest.post(rest.routes.channels.dm(), {
1157
- recipient_id: userId.toString()
820
+ body: {
821
+ recipient_id: userId
822
+ }
1158
823
  });
1159
824
  },
1160
825
  async getEmoji (guildId, emojiId) {
@@ -1164,7 +829,9 @@ export function createRestManager(options) {
1164
829
  return await rest.get(rest.routes.guilds.emojis(guildId));
1165
830
  },
1166
831
  async getFollowupMessage (token, messageId) {
1167
- return await rest.get(rest.routes.interactions.responses.message(rest.applicationId, token, messageId));
832
+ return await rest.get(rest.routes.interactions.responses.message(rest.applicationId, token, messageId), {
833
+ unauthorized: true
834
+ });
1168
835
  },
1169
836
  async getGatewayBot () {
1170
837
  return await rest.get(rest.routes.gatewayBot());
@@ -1217,7 +884,9 @@ export function createRestManager(options) {
1217
884
  return await rest.get(rest.routes.nitroStickerPacks());
1218
885
  },
1219
886
  async getOriginalInteractionResponse (token) {
1220
- return await rest.get(rest.routes.interactions.responses.original(rest.applicationId, token));
887
+ return await rest.get(rest.routes.interactions.responses.original(rest.applicationId, token), {
888
+ unauthorized: true
889
+ });
1221
890
  },
1222
891
  async getPinnedMessages (channelId) {
1223
892
  return await rest.get(rest.routes.channels.pins(channelId));
@@ -1298,77 +967,78 @@ export function createRestManager(options) {
1298
967
  return await rest.get(rest.routes.guilds.widget(guildId));
1299
968
  },
1300
969
  async joinThread (channelId) {
1301
- return await rest.put(rest.routes.channels.threads.me(channelId));
970
+ await rest.put(rest.routes.channels.threads.me(channelId));
1302
971
  },
1303
972
  async leaveGuild (guildId) {
1304
- return await rest.delete(rest.routes.guilds.leave(guildId));
973
+ await rest.delete(rest.routes.guilds.leave(guildId));
1305
974
  },
1306
975
  async leaveThread (channelId) {
1307
- return await rest.delete(rest.routes.channels.threads.me(channelId));
976
+ await rest.delete(rest.routes.channels.threads.me(channelId));
1308
977
  },
1309
978
  async publishMessage (channelId, messageId) {
1310
979
  return await rest.post(rest.routes.channels.crosspost(channelId, messageId));
1311
980
  },
1312
981
  async removeRole (guildId, userId, roleId, reason) {
1313
- return await rest.delete(rest.routes.guilds.roles.member(guildId, userId, roleId), {
982
+ await rest.delete(rest.routes.guilds.roles.member(guildId, userId, roleId), {
1314
983
  reason
1315
984
  });
1316
985
  },
1317
986
  async removeThreadMember (channelId, userId) {
1318
- return await rest.delete(rest.routes.channels.threads.user(channelId, userId));
987
+ await rest.delete(rest.routes.channels.threads.user(channelId, userId));
1319
988
  },
1320
989
  async sendFollowupMessage (token, options) {
1321
- return await new Promise((resolve, reject)=>{
1322
- rest.sendRequest({
1323
- url: rest.routes.webhooks.webhook(rest.applicationId, token),
1324
- method: 'POST',
1325
- body: options,
1326
- retryCount: 0,
1327
- retryRequest: async function(options) {
1328
- // TODO: should change to reprocess queue item
1329
- await rest.sendRequest(options);
1330
- },
1331
- resolve: (data)=>resolve(data.status !== 204 ? JSON.parse(data.body ?? '{}') : undefined),
1332
- reject
1333
- });
990
+ return await rest.post(rest.routes.webhooks.webhook(rest.applicationId, token), {
991
+ body: options,
992
+ files: options.files,
993
+ unauthorized: true
1334
994
  });
1335
995
  },
1336
996
  async sendInteractionResponse (interactionId, token, options) {
1337
- return await new Promise((resolve, reject)=>{
1338
- rest.sendRequest({
1339
- url: rest.routes.interactions.responses.callback(interactionId, token),
1340
- method: 'POST',
1341
- body: options,
1342
- retryCount: 0,
1343
- retryRequest: async function(options) {
1344
- // TODO: should change to reprocess queue item
1345
- await rest.sendRequest(options);
1346
- },
1347
- resolve: (data)=>resolve(data.status !== 204 ? JSON.parse(data.body ?? '{}') : undefined),
1348
- reject
1349
- });
997
+ return await rest.post(rest.routes.interactions.responses.callback(interactionId, token), {
998
+ body: options,
999
+ files: options.data?.files,
1000
+ runThroughQueue: false,
1001
+ unauthorized: true
1350
1002
  });
1351
1003
  },
1352
- async sendMessage (channelId, options) {
1353
- return await rest.post(rest.routes.channels.messages(channelId), options);
1004
+ async sendMessage (channelId, body) {
1005
+ return await rest.post(rest.routes.channels.messages(channelId), {
1006
+ body,
1007
+ files: body.files
1008
+ });
1354
1009
  },
1355
- async startThreadWithMessage (channelId, messageId, options) {
1356
- return await rest.post(rest.routes.channels.threads.message(channelId, messageId), options);
1010
+ async startThreadWithMessage (channelId, messageId, body, reason) {
1011
+ return await rest.post(rest.routes.channels.threads.message(channelId, messageId), {
1012
+ body,
1013
+ reason
1014
+ });
1357
1015
  },
1358
- async startThreadWithoutMessage (channelId, options) {
1359
- return await rest.post(rest.routes.channels.threads.all(channelId), options);
1016
+ async startThreadWithoutMessage (channelId, body, reason) {
1017
+ return await rest.post(rest.routes.channels.threads.all(channelId), {
1018
+ body,
1019
+ reason
1020
+ });
1360
1021
  },
1361
1022
  async syncGuildTemplate (guildId) {
1362
1023
  return await rest.put(rest.routes.guilds.templates.all(guildId));
1363
1024
  },
1364
- async banMember (guildId, userId, options) {
1365
- return await rest.put(rest.routes.guilds.members.ban(guildId, userId), options);
1025
+ async banMember (guildId, userId, body, reason) {
1026
+ await rest.put(rest.routes.guilds.members.ban(guildId, userId), {
1027
+ body,
1028
+ reason
1029
+ });
1366
1030
  },
1367
- async editBotMember (guildId, options) {
1368
- return await rest.patch(rest.routes.guilds.members.bot(guildId), options);
1031
+ async editBotMember (guildId, body, reason) {
1032
+ return await rest.patch(rest.routes.guilds.members.bot(guildId), {
1033
+ body,
1034
+ reason
1035
+ });
1369
1036
  },
1370
- async editMember (guildId, userId, options) {
1371
- return await rest.patch(rest.routes.guilds.members.member(guildId, userId), options);
1037
+ async editMember (guildId, userId, body, reason) {
1038
+ return await rest.patch(rest.routes.guilds.members.member(guildId, userId), {
1039
+ body,
1040
+ reason
1041
+ });
1372
1042
  },
1373
1043
  async getMember (guildId, userId) {
1374
1044
  return await rest.get(rest.routes.guilds.members.member(guildId, userId));
@@ -1377,40 +1047,56 @@ export function createRestManager(options) {
1377
1047
  return await rest.get(rest.routes.guilds.members.members(guildId, options));
1378
1048
  },
1379
1049
  async kickMember (guildId, userId, reason) {
1380
- return await rest.delete(rest.routes.guilds.members.member(guildId, userId), {
1050
+ await rest.delete(rest.routes.guilds.members.member(guildId, userId), {
1381
1051
  reason
1382
1052
  });
1383
1053
  },
1384
1054
  async pinMessage (channelId, messageId, reason) {
1385
- return await rest.put(rest.routes.channels.pin(channelId, messageId), reason ? {
1055
+ await rest.put(rest.routes.channels.pin(channelId, messageId), {
1386
1056
  reason
1387
- } : undefined);
1057
+ });
1388
1058
  },
1389
- async pruneMembers (guildId, options) {
1390
- return await rest.post(rest.routes.guilds.members.prune(guildId), options);
1059
+ async pruneMembers (guildId, body, reason) {
1060
+ return await rest.post(rest.routes.guilds.members.prune(guildId), {
1061
+ body,
1062
+ reason
1063
+ });
1391
1064
  },
1392
1065
  async searchMembers (guildId, query, options) {
1393
1066
  return await rest.get(rest.routes.guilds.members.search(guildId, query, options));
1394
1067
  },
1395
- async unbanMember (guildId, userId) {
1396
- return await rest.delete(rest.routes.guilds.members.ban(guildId, userId));
1068
+ async unbanMember (guildId, userId, reason) {
1069
+ await rest.delete(rest.routes.guilds.members.ban(guildId, userId), {
1070
+ reason
1071
+ });
1397
1072
  },
1398
1073
  async unpinMessage (channelId, messageId, reason) {
1399
- return await rest.delete(rest.routes.channels.pin(channelId, messageId), reason ? {
1074
+ await rest.delete(rest.routes.channels.pin(channelId, messageId), {
1400
1075
  reason
1401
- } : undefined);
1076
+ });
1402
1077
  },
1403
1078
  async triggerTypingIndicator (channelId) {
1404
- return await rest.post(rest.routes.channels.typing(channelId));
1079
+ await rest.post(rest.routes.channels.typing(channelId));
1405
1080
  },
1406
- async upsertGlobalApplicationCommands (commands) {
1407
- return await rest.put(rest.routes.interactions.commands.commands(rest.applicationId), commands);
1081
+ async upsertGlobalApplicationCommands (body) {
1082
+ return await rest.put(rest.routes.interactions.commands.commands(rest.applicationId), {
1083
+ body
1084
+ });
1408
1085
  },
1409
- async upsertGuildApplicationCommands (guildId, commands) {
1410
- return await rest.put(rest.routes.interactions.commands.guilds.all(rest.applicationId, guildId), commands);
1086
+ async upsertGuildApplicationCommands (guildId, body) {
1087
+ return await rest.put(rest.routes.interactions.commands.guilds.all(rest.applicationId, guildId), {
1088
+ body
1089
+ });
1411
1090
  }
1412
1091
  };
1413
1092
  return rest;
1414
1093
  }
1094
+ var HttpResponseCode;
1095
+ (function(HttpResponseCode) {
1096
+ HttpResponseCode[HttpResponseCode[/** Minimum value of a code in oder to consider that it was successful. */ "Success"] = 200] = "Success";
1097
+ HttpResponseCode[HttpResponseCode[/** Request completed successfully, but Discord returned an empty body. */ "NoContent"] = 204] = "NoContent";
1098
+ HttpResponseCode[HttpResponseCode[/** Minimum value of a code in order to consider that something went wrong. */ "Error"] = 400] = "Error";
1099
+ HttpResponseCode[HttpResponseCode[/** This request got rate limited. */ "TooManyRequests"] = 429] = "TooManyRequests";
1100
+ })(HttpResponseCode || (HttpResponseCode = {}));
1415
1101
 
1416
1102
  //# sourceMappingURL=manager.js.map