@discordeno/rest 19.0.0-next.da74ea7 → 19.0.0-next.dbf4fda

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.
Files changed (52) hide show
  1. package/README.md +15 -1
  2. package/dist/cjs/index.cjs +25 -0
  3. package/dist/cjs/invalidBucket.cjs +86 -0
  4. package/dist/cjs/manager.cjs +1535 -0
  5. package/dist/cjs/queue.cjs +164 -0
  6. package/dist/cjs/routes.cjs +589 -0
  7. package/dist/cjs/types.cjs +6 -0
  8. package/dist/cjs/typings/routes.cjs +6 -0
  9. package/dist/esm/index.js +8 -0
  10. package/dist/esm/invalidBucket.js +82 -0
  11. package/dist/esm/manager.js +1493 -0
  12. package/dist/esm/queue.js +154 -0
  13. package/dist/esm/routes.js +579 -0
  14. package/dist/esm/types.js +3 -0
  15. package/dist/esm/typings/routes.js +3 -0
  16. package/dist/types/index.d.ts.map +1 -0
  17. package/dist/{invalidBucket.d.ts → types/invalidBucket.d.ts} +11 -7
  18. package/dist/types/invalidBucket.d.ts.map +1 -0
  19. package/dist/types/manager.d.ts +12 -0
  20. package/dist/types/manager.d.ts.map +1 -0
  21. package/dist/{queue.d.ts → types/queue.d.ts} +12 -1
  22. package/dist/types/queue.d.ts.map +1 -0
  23. package/dist/types/routes.d.ts.map +1 -0
  24. package/dist/{types.d.ts → types/types.d.ts} +647 -117
  25. package/dist/types/types.d.ts.map +1 -0
  26. package/dist/{typings → types/typings}/routes.d.ts +69 -6
  27. package/dist/types/typings/routes.d.ts.map +1 -0
  28. package/package.json +33 -30
  29. package/dist/index.d.ts.map +0 -1
  30. package/dist/index.js +0 -8
  31. package/dist/index.js.map +0 -1
  32. package/dist/invalidBucket.d.ts.map +0 -1
  33. package/dist/invalidBucket.js +0 -84
  34. package/dist/invalidBucket.js.map +0 -1
  35. package/dist/manager.d.ts +0 -3
  36. package/dist/manager.d.ts.map +0 -1
  37. package/dist/manager.js +0 -1090
  38. package/dist/manager.js.map +0 -1
  39. package/dist/queue.d.ts.map +0 -1
  40. package/dist/queue.js +0 -153
  41. package/dist/queue.js.map +0 -1
  42. package/dist/routes.d.ts.map +0 -1
  43. package/dist/routes.js +0 -487
  44. package/dist/routes.js.map +0 -1
  45. package/dist/types.d.ts.map +0 -1
  46. package/dist/types.js +0 -3
  47. package/dist/types.js.map +0 -1
  48. package/dist/typings/routes.d.ts.map +0 -1
  49. package/dist/typings/routes.js +0 -3
  50. package/dist/typings/routes.js.map +0 -1
  51. /package/dist/{index.d.ts → types/index.d.ts} +0 -0
  52. /package/dist/{routes.d.ts → types/routes.d.ts} +0 -0
package/dist/manager.js DELETED
@@ -1,1090 +0,0 @@
1
- /* eslint-disable @typescript-eslint/restrict-template-expressions */ /* eslint-disable no-const-assign */ import { InteractionResponseTypes } from '@discordeno/types';
2
- import { calculateBits, camelize, camelToSnakeCase, delay, getBotIdFromToken, logger, processReactionString, urlToBase64 } from '@discordeno/utils';
3
- import fetch from 'node-fetch';
4
- import { createInvalidRequestBucket } from './invalidBucket.js';
5
- import { Queue } from './queue.js';
6
- import { createRoutes } from './routes.js';
7
- // TODO: make dynamic based on package.json file
8
- const version = '19.0.0-alpha.1';
9
- export function createRestManager(options) {
10
- const applicationId = options.applicationId ? BigInt(options.applicationId) : options.token ? getBotIdFromToken(options.token) : undefined;
11
- if (!applicationId) {
12
- 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.');
13
- }
14
- const rest = {
15
- token: options.token,
16
- applicationId,
17
- version: options.version ?? 10,
18
- baseUrl: options.proxy?.baseUrl ?? 'https://discord.com/api',
19
- maxRetryCount: Infinity,
20
- globallyRateLimited: false,
21
- processingRateLimitedPaths: false,
22
- deleteQueueDelay: 60000,
23
- queues: new Map(),
24
- rateLimitedPaths: new Map(),
25
- invalidBucket: createInvalidRequestBucket({}),
26
- authorization: options.proxy?.authorization,
27
- routes: createRoutes(),
28
- checkRateLimits (url) {
29
- const ratelimited = rest.rateLimitedPaths.get(url);
30
- const global = rest.rateLimitedPaths.get('global');
31
- const now = Date.now();
32
- if (ratelimited && now < ratelimited.resetTimestamp) {
33
- return ratelimited.resetTimestamp - now;
34
- }
35
- if (global && now < global.resetTimestamp) {
36
- return global.resetTimestamp - now;
37
- }
38
- return false;
39
- },
40
- changeToDiscordFormat (obj) {
41
- if (obj === null) return null;
42
- if (typeof obj === 'object') {
43
- if (Array.isArray(obj)) {
44
- return obj.map((item)=>rest.changeToDiscordFormat(item));
45
- }
46
- const newObj = {};
47
- for (const key of Object.keys(obj)){
48
- // Keys that dont require snake casing
49
- if ([
50
- 'permissions',
51
- 'allow',
52
- 'deny'
53
- ].includes(key)) {
54
- newObj[key] = calculateBits(obj[key]);
55
- continue;
56
- }
57
- if (key === 'defaultMemberPermissions') {
58
- newObj.default_member_permissions = calculateBits(obj[key]);
59
- continue;
60
- }
61
- newObj[camelToSnakeCase(key)] = rest.changeToDiscordFormat(obj[key]);
62
- }
63
- return newObj;
64
- }
65
- if (typeof obj === 'bigint') return obj.toString();
66
- return obj;
67
- },
68
- createRequestBody (method, options) {
69
- const headers = {
70
- 'user-agent': `DiscordBot (https://github.com/discordeno/discordeno, v${version})`
71
- };
72
- if (options?.unauthorized !== false) headers.authorization = `Bot ${rest.token}`;
73
- // IF A REASON IS PROVIDED ENCODE IT IN HEADERS
74
- if (options?.reason !== undefined) {
75
- headers['x-audit-log-reason'] = encodeURIComponent(options?.reason);
76
- }
77
- let body;
78
- // TODO: check if we need to add specific check for GET method
79
- // Since GET does not allow bodies
80
- // Have to check for attachments first, since body then has to be send in a different way.
81
- if (options?.files !== undefined) {
82
- const form = new FormData();
83
- for(let i = 0; i < options.files.length; ++i){
84
- form.append(`file${i}`, options.files[i].blob, options.files[i].name);
85
- }
86
- form.append('payload_json', JSON.stringify({
87
- ...options.body,
88
- files: undefined
89
- }));
90
- body = form;
91
- // No need to set the `content-type` header since `fetch` does that automatically for us when we use a `FormData` object.
92
- } else if (options?.body !== undefined) {
93
- if (options.body instanceof FormData) {
94
- body = options.body;
95
- // No need to set the `content-type` header since `fetch` does that automatically for us when we use a `FormData` object.
96
- } else {
97
- body = JSON.stringify(rest.changeToDiscordFormat(options.body));
98
- headers['content-type'] = `application/json`;
99
- }
100
- }
101
- // SOMETIMES SPECIAL HEADERS (E.G. CUSTOM AUTHORIZATION) NEED TO BE USED
102
- if (options?.headers) {
103
- Object.assign(headers, options.headers);
104
- }
105
- return {
106
- body,
107
- headers,
108
- method
109
- };
110
- },
111
- processRateLimitedPaths () {
112
- const now = Date.now();
113
- for (const [key, value] of rest.rateLimitedPaths.entries()){
114
- // rest.debug(
115
- // `[REST - processRateLimitedPaths] Running for of loop. ${
116
- // value.resetTimestamp - now
117
- // }`
118
- // )
119
- // If the time has not reached cancel
120
- if (value.resetTimestamp > now) continue;
121
- // Rate limit is over, delete the rate limiter
122
- rest.rateLimitedPaths.delete(key);
123
- // If it was global, also mark the global value as false
124
- if (key === 'global') rest.globallyRateLimited = false;
125
- }
126
- // ALL PATHS ARE CLEARED CAN CANCEL OUT!
127
- if (rest.rateLimitedPaths.size === 0) {
128
- rest.processingRateLimitedPaths = false;
129
- } else {
130
- rest.processingRateLimitedPaths = true;
131
- // RECHECK IN 1 SECOND
132
- setTimeout(()=>{
133
- // rest.debug('[REST - processRateLimitedPaths] Running setTimeout.')
134
- rest.processRateLimitedPaths();
135
- }, 1000);
136
- }
137
- },
138
- /** Processes the rate limit headers and determines if it needs to be rate limited and returns the bucket id if available */ processHeaders (url, headers) {
139
- let rateLimited = false;
140
- // GET ALL NECESSARY HEADERS
141
- const remaining = headers.get('x-ratelimit-remaining');
142
- const retryAfter = headers.get('x-ratelimit-reset-after');
143
- const reset = Date.now() + Number(retryAfter) * 1000;
144
- const global = headers.get('x-ratelimit-global');
145
- // undefined override null needed for typings
146
- const bucketId = headers.get('x-ratelimit-bucket') ?? undefined;
147
- const limit = headers.get('x-ratelimit-limit');
148
- rest.queues.get(url)?.handleCompletedRequest({
149
- remaining: remaining ? Number(remaining) : undefined,
150
- interval: retryAfter ? Number(retryAfter) * 1000 : undefined,
151
- max: limit ? Number(limit) : undefined
152
- });
153
- // IF THERE IS NO REMAINING RATE LIMIT, MARK IT AS RATE LIMITED
154
- if (remaining === '0') {
155
- rateLimited = true;
156
- // SAVE THE URL AS LIMITED, IMPORTANT FOR NEW REQUESTS BY USER WITHOUT BUCKET
157
- rest.rateLimitedPaths.set(url, {
158
- url,
159
- resetTimestamp: reset,
160
- bucketId
161
- });
162
- // SAVE THE BUCKET AS LIMITED SINCE DIFFERENT URLS MAY SHARE A BUCKET
163
- if (bucketId) {
164
- rest.rateLimitedPaths.set(bucketId, {
165
- url,
166
- resetTimestamp: reset,
167
- bucketId
168
- });
169
- }
170
- }
171
- // IF THERE IS NO REMAINING GLOBAL LIMIT, MARK IT RATE LIMITED GLOBALLY
172
- if (global) {
173
- const retryAfter = headers.get('retry-after');
174
- const globalReset = Date.now() + Number(retryAfter) * 1000;
175
- // rest.debug(
176
- // `[REST = Globally Rate Limited] URL: ${url} | Global Rest: ${globalReset}`
177
- // )
178
- rest.globallyRateLimited = true;
179
- rateLimited = true;
180
- setTimeout(()=>{
181
- rest.globallyRateLimited = false;
182
- }, globalReset);
183
- rest.rateLimitedPaths.set('global', {
184
- url: 'global',
185
- resetTimestamp: globalReset,
186
- bucketId
187
- });
188
- if (bucketId) {
189
- rest.rateLimitedPaths.set(bucketId, {
190
- url: 'global',
191
- resetTimestamp: globalReset,
192
- bucketId
193
- });
194
- }
195
- }
196
- if (rateLimited && !rest.processingRateLimitedPaths) {
197
- rest.processRateLimitedPaths();
198
- }
199
- return rateLimited ? bucketId : undefined;
200
- },
201
- async sendRequest (options) {
202
- const url = options.url.startsWith('https://') ? options.url : `${rest.baseUrl}/v${rest.version}${options.url}`;
203
- const payload = rest.createRequestBody(options.method, options.requestBodyOptions);
204
- logger.debug(`sending request to ${url}`, 'with payload:', {
205
- ...payload,
206
- headers: {
207
- ...payload.headers,
208
- authorization: 'Bot tokenhere'
209
- }
210
- });
211
- const response = await fetch(url, payload);
212
- logger.debug(`request fetched from ${url} with status ${response.status} & ${response.statusText}`);
213
- // Set the bucket id if it was available on the headers
214
- const bucketId = rest.processHeaders(rest.simplifyUrl(options.url, options.method), response.headers);
215
- if (bucketId) options.bucketId = bucketId;
216
- if (response.status < 200 || response.status >= 400) {
217
- logger.debug(`Request to ${url} failed.`);
218
- if (response.status === 429) {
219
- logger.debug(`Request to ${url} was ratelimited.`);
220
- // Too many attempts, get rid of request from queue.
221
- if (options.retryCount++ >= rest.maxRetryCount) {
222
- logger.debug(`Request to ${url} exceeded the maximum allowed retries.`, 'with payload:', payload);
223
- // rest.debug(`[REST - RetriesMaxed] ${JSON.stringify(options)}`)
224
- // Remove item from queue to prevent retry
225
- options.reject({
226
- ok: false,
227
- status: response.status,
228
- error: 'The options was rate limited and it maxed out the retries limit.'
229
- });
230
- return;
231
- }
232
- // Rate limited, add back to queue
233
- rest.invalidBucket.handleCompletedRequest(response.status, response.headers.get('X-RateLimit-Scope') === 'shared');
234
- const resetAfter = response.headers.get('x-ratelimit-reset-after');
235
- if (resetAfter) await delay(Number(resetAfter) * 1000);
236
- // process the response to prevent mem leak
237
- await response.json();
238
- return await options.retryRequest?.(options);
239
- }
240
- options.reject({
241
- ok: false,
242
- status: response.status,
243
- body: JSON.stringify(await response.json())
244
- });
245
- return;
246
- }
247
- const is204 = response.status === 204;
248
- const json = is204 ? undefined : await response.json();
249
- // Discord sometimes sends no response with 204 code
250
- options.resolve({
251
- ok: true,
252
- status: response.status,
253
- body: JSON.stringify(json)
254
- });
255
- },
256
- simplifyUrl (url, method) {
257
- const parts = url.split('/');
258
- const secondLastPart = parts[parts.length - 2];
259
- if (secondLastPart === 'channels' || secondLastPart === 'guilds') {
260
- return url;
261
- }
262
- if (secondLastPart === 'reactions' || parts[parts.length - 1] === '@me') {
263
- parts.splice(-2);
264
- parts.push('reactions');
265
- } else {
266
- parts.splice(-1);
267
- parts.push('x');
268
- }
269
- if (parts[parts.length - 3] === 'reactions') {
270
- parts.splice(-2);
271
- }
272
- if (method === 'DELETE' && secondLastPart === 'messages') {
273
- return `D${parts.join('/')}`;
274
- }
275
- return parts.join('/');
276
- },
277
- async processRequest (request) {
278
- const route = request.url.substring(request.url.indexOf('api/'));
279
- const parts = route.split('/');
280
- // Remove the api/
281
- parts.shift();
282
- // Removes the /v#/
283
- if (parts[0]?.startsWith('v')) parts.shift();
284
- // Set the full url to discord api in case it was recieved in a proxy rest
285
- request.url = `${rest.baseUrl}/v${rest.version}/${parts.join('/')}`;
286
- const url = rest.simplifyUrl(request.url, request.method);
287
- if (request.runThroughQueue === false) {
288
- await rest.sendRequest(request);
289
- return;
290
- }
291
- const queue = rest.queues.get(url);
292
- if (queue !== undefined) {
293
- queue.makeRequest(request);
294
- } else {
295
- // CREATES A NEW QUEUE
296
- const bucketQueue = new Queue(rest, {
297
- url,
298
- deleteQueueDelay: rest.deleteQueueDelay
299
- });
300
- // Add request to queue
301
- bucketQueue.makeRequest(request);
302
- // Save queue
303
- rest.queues.set(url, bucketQueue);
304
- }
305
- },
306
- async makeRequest (method, url, options) {
307
- if (!rest.baseUrl.startsWith('https://discord.com') && url[0] === '/') {
308
- const result = await fetch(`${rest.baseUrl}${url}`, rest.createRequestBody(method, options));
309
- if (!result.ok) {
310
- const err = await result.json().catch(()=>{});
311
- // Legacy Handling to not break old code or when body is missing
312
- if (!err?.body) throw new Error(`Error: ${err.message ?? result.statusText}`);
313
- throw new Error(JSON.stringify(err));
314
- }
315
- return result.status !== 204 ? await result.json() : undefined;
316
- }
317
- // eslint-disable-next-line no-async-promise-executor
318
- return await new Promise(async (resolve, reject)=>{
319
- const payload = {
320
- url,
321
- method,
322
- requestBodyOptions: options,
323
- retryCount: 0,
324
- retryRequest: async function(payload) {
325
- await rest.processRequest(payload);
326
- },
327
- resolve: (data)=>{
328
- resolve(data.status !== 204 ? JSON.parse(data.body ?? '{}') : undefined);
329
- },
330
- reject,
331
- runThroughQueue: options?.runThroughQueue
332
- };
333
- await rest.processRequest(payload);
334
- });
335
- },
336
- async get (url, options) {
337
- return camelize(await rest.makeRequest('GET', url, options));
338
- },
339
- async post (url, options) {
340
- return camelize(await rest.makeRequest('POST', url, options));
341
- },
342
- async delete (url, options) {
343
- camelize(await rest.makeRequest('DELETE', url, options));
344
- },
345
- async patch (url, options) {
346
- return camelize(await rest.makeRequest('PATCH', url, options));
347
- },
348
- async put (url, options) {
349
- return camelize(await rest.makeRequest('PUT', url, options));
350
- },
351
- async addReaction (channelId, messageId, reaction) {
352
- reaction = processReactionString(reaction);
353
- await rest.put(rest.routes.channels.reactions.bot(channelId, messageId, reaction));
354
- },
355
- async addReactions (channelId, messageId, reactions, ordered = false) {
356
- if (!ordered) {
357
- await Promise.all(reactions.map(async (reaction)=>{
358
- await rest.addReaction(channelId, messageId, reaction);
359
- }));
360
- return;
361
- }
362
- for (const reaction of reactions){
363
- await rest.addReaction(channelId, messageId, reaction);
364
- }
365
- },
366
- async addRole (guildId, userId, roleId, reason) {
367
- await rest.put(rest.routes.guilds.roles.member(guildId, userId, roleId), {
368
- reason
369
- });
370
- },
371
- async addThreadMember (channelId, userId) {
372
- await rest.put(rest.routes.channels.threads.user(channelId, userId));
373
- },
374
- async createAutomodRule (guildId, body, reason) {
375
- return await rest.post(rest.routes.guilds.automod.rules(guildId), {
376
- body,
377
- reason
378
- });
379
- },
380
- async createChannel (guildId, body, reason) {
381
- return await rest.post(rest.routes.guilds.channels(guildId), {
382
- body,
383
- reason
384
- });
385
- },
386
- async createEmoji (guildId, body, reason) {
387
- return await rest.post(rest.routes.guilds.emojis(guildId), {
388
- body,
389
- reason
390
- });
391
- },
392
- async createGlobalApplicationCommand (body) {
393
- return await rest.post(rest.routes.interactions.commands.commands(rest.applicationId), {
394
- body
395
- });
396
- },
397
- async createGuild (body) {
398
- return await rest.post(rest.routes.guilds.all(), {
399
- body
400
- });
401
- },
402
- async createGuildApplicationCommand (body, guildId) {
403
- return await rest.post(rest.routes.interactions.commands.guilds.all(rest.applicationId, guildId), {
404
- body
405
- });
406
- },
407
- async createGuildFromTemplate (templateCode, body) {
408
- if (body.icon) {
409
- body.icon = await urlToBase64(body.icon);
410
- }
411
- return await rest.post(rest.routes.guilds.templates.code(templateCode), {
412
- body
413
- });
414
- },
415
- async createGuildSticker (guildId, options, reason) {
416
- const form = new FormData();
417
- form.append('file', options.file.blob, options.file.name);
418
- form.append('name', options.name);
419
- form.append('description', options.description);
420
- form.append('tags', options.tags);
421
- return await rest.post(rest.routes.guilds.stickers(guildId), {
422
- body: form,
423
- reason
424
- });
425
- },
426
- async createGuildTemplate (guildId, body) {
427
- return await rest.post(rest.routes.guilds.templates.all(guildId), {
428
- body
429
- });
430
- },
431
- async createForumThread (channelId, body, reason) {
432
- return await rest.post(rest.routes.channels.forum(channelId), {
433
- body,
434
- files: body.files,
435
- reason
436
- });
437
- },
438
- async createInvite (channelId, body = {}, reason) {
439
- return await rest.post(rest.routes.channels.invites(channelId), {
440
- body,
441
- reason
442
- });
443
- },
444
- async createRole (guildId, body, reason) {
445
- return await rest.post(rest.routes.guilds.roles.all(guildId), {
446
- body,
447
- reason
448
- });
449
- },
450
- async createScheduledEvent (guildId, body, reason) {
451
- return await rest.post(rest.routes.guilds.events.events(guildId), {
452
- body,
453
- reason
454
- });
455
- },
456
- async createStageInstance (body, reason) {
457
- return await rest.post(rest.routes.channels.stages(), {
458
- body,
459
- reason
460
- });
461
- },
462
- async createWebhook (channelId, options, reason) {
463
- return await rest.post(rest.routes.channels.webhooks(channelId), {
464
- body: {
465
- name: options.name,
466
- avatar: options.avatar ? await urlToBase64(options.avatar) : undefined
467
- },
468
- reason
469
- });
470
- },
471
- async deleteAutomodRule (guildId, ruleId, reason) {
472
- await rest.delete(rest.routes.guilds.automod.rule(guildId, ruleId), {
473
- reason
474
- });
475
- },
476
- async deleteChannel (channelId, reason) {
477
- await rest.delete(rest.routes.channels.channel(channelId), {
478
- reason
479
- });
480
- },
481
- async deleteChannelPermissionOverride (channelId, overwriteId, reason) {
482
- await rest.delete(rest.routes.channels.overwrite(channelId, overwriteId), {
483
- reason
484
- });
485
- },
486
- async deleteEmoji (guildId, id, reason) {
487
- await rest.delete(rest.routes.guilds.emoji(guildId, id), {
488
- reason
489
- });
490
- },
491
- async deleteFollowupMessage (token, messageId) {
492
- await rest.delete(rest.routes.interactions.responses.message(rest.applicationId, token, messageId), {
493
- unauthorized: true
494
- });
495
- },
496
- async deleteGlobalApplicationCommand (commandId) {
497
- await rest.delete(rest.routes.interactions.commands.command(rest.applicationId, commandId));
498
- },
499
- async deleteGuild (guildId) {
500
- await rest.delete(rest.routes.guilds.guild(guildId));
501
- },
502
- async deleteGuildApplicationCommand (commandId, guildId) {
503
- await rest.delete(rest.routes.interactions.commands.guilds.one(rest.applicationId, guildId, commandId));
504
- },
505
- async deleteGuildSticker (guildId, stickerId, reason) {
506
- await rest.delete(rest.routes.guilds.sticker(guildId, stickerId), {
507
- reason
508
- });
509
- },
510
- async deleteGuildTemplate (guildId, templateCode) {
511
- await rest.delete(rest.routes.guilds.templates.guild(guildId, templateCode));
512
- },
513
- async deleteIntegration (guildId, integrationId, reason) {
514
- await rest.delete(rest.routes.guilds.integration(guildId, integrationId), {
515
- reason
516
- });
517
- },
518
- async deleteInvite (inviteCode, reason) {
519
- await rest.delete(rest.routes.guilds.invite(inviteCode), {
520
- reason
521
- });
522
- },
523
- async deleteMessage (channelId, messageId, reason) {
524
- await rest.delete(rest.routes.channels.message(channelId, messageId), {
525
- reason
526
- });
527
- },
528
- async deleteMessages (channelId, messageIds, reason) {
529
- await rest.post(rest.routes.channels.bulk(channelId), {
530
- body: {
531
- messages: messageIds.slice(0, 100).map((id)=>id.toString())
532
- },
533
- reason
534
- });
535
- },
536
- async deleteOriginalInteractionResponse (token) {
537
- await rest.delete(rest.routes.interactions.responses.original(rest.applicationId, token), {
538
- unauthorized: true
539
- });
540
- },
541
- async deleteOwnReaction (channelId, messageId, reaction) {
542
- reaction = processReactionString(reaction);
543
- await rest.delete(rest.routes.channels.reactions.bot(channelId, messageId, reaction));
544
- },
545
- async deleteReactionsAll (channelId, messageId) {
546
- await rest.delete(rest.routes.channels.reactions.all(channelId, messageId));
547
- },
548
- async deleteReactionsEmoji (channelId, messageId, reaction) {
549
- reaction = processReactionString(reaction);
550
- await rest.delete(rest.routes.channels.reactions.emoji(channelId, messageId, reaction));
551
- },
552
- async deleteRole (guildId, roleId, reason) {
553
- await rest.delete(rest.routes.guilds.roles.one(guildId, roleId), {
554
- reason
555
- });
556
- },
557
- async deleteScheduledEvent (guildId, eventId) {
558
- await rest.delete(rest.routes.guilds.events.event(guildId, eventId));
559
- },
560
- async deleteStageInstance (channelId, reason) {
561
- await rest.delete(rest.routes.channels.stage(channelId), {
562
- reason
563
- });
564
- },
565
- async deleteUserReaction (channelId, messageId, userId, reaction) {
566
- reaction = processReactionString(reaction);
567
- await rest.delete(rest.routes.channels.reactions.user(channelId, messageId, reaction, userId));
568
- },
569
- async deleteWebhook (webhookId, reason) {
570
- await rest.delete(rest.routes.webhooks.id(webhookId), {
571
- reason
572
- });
573
- },
574
- async deleteWebhookMessage (webhookId, token, messageId, options) {
575
- await rest.delete(rest.routes.webhooks.message(webhookId, token, messageId, options));
576
- },
577
- async deleteWebhookWithToken (webhookId, token) {
578
- await rest.delete(rest.routes.webhooks.webhook(webhookId, token));
579
- },
580
- async editApplicationCommandPermissions (guildId, commandId, bearerToken, permissions) {
581
- return await rest.put(rest.routes.interactions.commands.permission(rest.applicationId, guildId, commandId), {
582
- body: {
583
- permissions
584
- },
585
- headers: {
586
- authorization: `Bearer ${bearerToken}`
587
- }
588
- });
589
- },
590
- async editAutomodRule (guildId, ruleId, body, reason) {
591
- return await rest.patch(rest.routes.guilds.automod.rule(guildId, ruleId), {
592
- body,
593
- reason
594
- });
595
- },
596
- async editBotProfile (options) {
597
- const avatar = options?.botAvatarURL ? await urlToBase64(options?.botAvatarURL) : options?.botAvatarURL;
598
- return await rest.patch(rest.routes.userBot(), {
599
- body: {
600
- username: options.username?.trim(),
601
- avatar
602
- }
603
- });
604
- },
605
- async editChannel (channelId, body, reason) {
606
- return await rest.patch(rest.routes.channels.channel(channelId), {
607
- body,
608
- reason
609
- });
610
- },
611
- async editChannelPermissionOverrides (channelId, body, reason) {
612
- await rest.put(rest.routes.channels.overwrite(channelId, body.id), {
613
- body,
614
- reason
615
- });
616
- },
617
- async editChannelPositions (guildId, body) {
618
- await rest.patch(rest.routes.guilds.channels(guildId), {
619
- body
620
- });
621
- },
622
- async editEmoji (guildId, id, body, reason) {
623
- return await rest.patch(rest.routes.guilds.emoji(guildId, id), {
624
- body,
625
- reason
626
- });
627
- },
628
- async editFollowupMessage (token, messageId, body) {
629
- return await rest.patch(rest.routes.interactions.responses.message(rest.applicationId, token, messageId), {
630
- body,
631
- files: body.files,
632
- unauthorized: true
633
- });
634
- },
635
- async editGlobalApplicationCommand (commandId, body) {
636
- return await rest.patch(rest.routes.interactions.commands.command(rest.applicationId, commandId), {
637
- body
638
- });
639
- },
640
- async editGuild (guildId, body, reason) {
641
- return await rest.patch(rest.routes.guilds.guild(guildId), {
642
- body,
643
- reason
644
- });
645
- },
646
- async editGuildApplicationCommand (commandId, guildId, body) {
647
- return await rest.patch(rest.routes.interactions.commands.guilds.one(rest.applicationId, guildId, commandId), {
648
- body
649
- });
650
- },
651
- async editGuildMfaLevel (guildId, mfaLevel, reason) {
652
- await rest.post(rest.routes.guilds.mfa(guildId), {
653
- body: {
654
- level: mfaLevel
655
- },
656
- reason
657
- });
658
- },
659
- async editGuildSticker (guildId, stickerId, body, reason) {
660
- return await rest.patch(rest.routes.guilds.sticker(guildId, stickerId), {
661
- body,
662
- reason
663
- });
664
- },
665
- async editGuildTemplate (guildId, templateCode, body) {
666
- return await rest.patch(rest.routes.guilds.templates.guild(guildId, templateCode), {
667
- body
668
- });
669
- },
670
- async editMessage (channelId, messageId, body) {
671
- return await rest.patch(rest.routes.channels.message(channelId, messageId), {
672
- body
673
- });
674
- },
675
- async editOriginalInteractionResponse (token, body) {
676
- return await rest.patch(rest.routes.interactions.responses.original(rest.applicationId, token), {
677
- body,
678
- files: body.files
679
- });
680
- },
681
- async editOriginalWebhookMessage (webhookId, token, options) {
682
- return await rest.patch(rest.routes.webhooks.original(webhookId, token, options), {
683
- body: {
684
- type: InteractionResponseTypes.UpdateMessage,
685
- data: options
686
- },
687
- files: options.files,
688
- unauthorized: true
689
- });
690
- },
691
- async editOwnVoiceState (guildId, options) {
692
- await rest.patch(rest.routes.guilds.voice(guildId), {
693
- body: {
694
- ...options,
695
- request_to_speak_timestamp: options.requestToSpeakTimestamp ? new Date(options.requestToSpeakTimestamp).toISOString() : options.requestToSpeakTimestamp
696
- }
697
- });
698
- },
699
- async editScheduledEvent (guildId, eventId, body, reason) {
700
- return await rest.patch(rest.routes.guilds.events.event(guildId, eventId), {
701
- body,
702
- reason
703
- });
704
- },
705
- async editRole (guildId, roleId, body, reason) {
706
- return await rest.patch(rest.routes.guilds.roles.one(guildId, roleId), {
707
- body,
708
- reason
709
- });
710
- },
711
- async editRolePositions (guildId, body, reason) {
712
- return await rest.patch(rest.routes.guilds.roles.all(guildId), {
713
- body,
714
- reason
715
- });
716
- },
717
- async editStageInstance (channelId, topic, reason) {
718
- return await rest.patch(rest.routes.channels.stage(channelId), {
719
- body: {
720
- topic
721
- },
722
- reason
723
- });
724
- },
725
- async editUserVoiceState (guildId, options) {
726
- await rest.patch(rest.routes.guilds.voice(guildId, options.userId), {
727
- body: options
728
- });
729
- },
730
- async editWebhook (webhookId, body, reason) {
731
- return await rest.patch(rest.routes.webhooks.id(webhookId), {
732
- body,
733
- reason
734
- });
735
- },
736
- async editWebhookMessage (webhookId, token, messageId, options) {
737
- return await rest.patch(rest.routes.webhooks.message(webhookId, token, messageId, options), {
738
- body: options,
739
- files: options.files
740
- });
741
- },
742
- async editWebhookWithToken (webhookId, token, body) {
743
- return await rest.patch(rest.routes.webhooks.webhook(webhookId, token), {
744
- body
745
- });
746
- },
747
- async editWelcomeScreen (guildId, body, reason) {
748
- return await rest.patch(rest.routes.guilds.welcome(guildId), {
749
- body,
750
- reason
751
- });
752
- },
753
- async editWidgetSettings (guildId, body, reason) {
754
- return await rest.patch(rest.routes.guilds.widget(guildId), {
755
- body,
756
- reason
757
- });
758
- },
759
- async executeWebhook (webhookId, token, options) {
760
- return await rest.post(rest.routes.webhooks.webhook(webhookId, token, options), {
761
- body: options
762
- });
763
- },
764
- async followAnnouncement (sourceChannelId, targetChannelId) {
765
- return await rest.post(rest.routes.channels.follow(sourceChannelId), {
766
- body: {
767
- webhook_channel_id: targetChannelId
768
- }
769
- });
770
- },
771
- async getActiveThreads (guildId) {
772
- return await rest.get(rest.routes.channels.threads.active(guildId));
773
- },
774
- async getApplicationCommandPermission (guildId, commandId) {
775
- return await rest.get(rest.routes.interactions.commands.permission(rest.applicationId, guildId, commandId));
776
- },
777
- async getApplicationCommandPermissions (guildId) {
778
- return await rest.get(rest.routes.interactions.commands.permissions(rest.applicationId, guildId));
779
- },
780
- async getApplicationInfo () {
781
- return await rest.get(rest.routes.oauth2Application());
782
- },
783
- async getAuditLog (guildId, options) {
784
- return await rest.get(rest.routes.guilds.auditlogs(guildId, options));
785
- },
786
- async getAutomodRule (guildId, ruleId) {
787
- return await rest.get(rest.routes.guilds.automod.rule(guildId, ruleId));
788
- },
789
- async getAutomodRules (guildId) {
790
- return await rest.get(rest.routes.guilds.automod.rules(guildId));
791
- },
792
- async getAvailableVoiceRegions () {
793
- return await rest.get(rest.routes.regions());
794
- },
795
- async getBan (guildId, userId) {
796
- return await rest.get(rest.routes.guilds.members.ban(guildId, userId));
797
- },
798
- async getBans (guildId, options) {
799
- return await rest.get(rest.routes.guilds.members.bans(guildId, options));
800
- },
801
- async getChannel (id) {
802
- return await rest.get(rest.routes.channels.channel(id));
803
- },
804
- async getChannelInvites (channelId) {
805
- return await rest.get(rest.routes.channels.invites(channelId));
806
- },
807
- async getChannels (guildId) {
808
- return await rest.get(rest.routes.guilds.channels(guildId));
809
- },
810
- async getChannelWebhooks (channelId) {
811
- return await rest.get(rest.routes.channels.webhooks(channelId));
812
- },
813
- async getDmChannel (userId) {
814
- return await rest.post(rest.routes.channels.dm(), {
815
- body: {
816
- recipient_id: userId
817
- }
818
- });
819
- },
820
- async getEmoji (guildId, emojiId) {
821
- return await rest.get(rest.routes.guilds.emoji(guildId, emojiId));
822
- },
823
- async getEmojis (guildId) {
824
- return await rest.get(rest.routes.guilds.emojis(guildId));
825
- },
826
- async getFollowupMessage (token, messageId) {
827
- return await rest.get(rest.routes.interactions.responses.message(rest.applicationId, token, messageId), {
828
- unauthorized: true
829
- });
830
- },
831
- async getGatewayBot () {
832
- return await rest.get(rest.routes.gatewayBot());
833
- },
834
- async getGlobalApplicationCommand (commandId) {
835
- return await rest.get(rest.routes.interactions.commands.command(rest.applicationId, commandId));
836
- },
837
- async getGlobalApplicationCommands () {
838
- return await rest.get(rest.routes.interactions.commands.commands(rest.applicationId));
839
- },
840
- async getGuild (guildId, options = {
841
- counts: true
842
- }) {
843
- return await rest.get(rest.routes.guilds.guild(guildId, options.counts));
844
- },
845
- async getGuildApplicationCommand (commandId, guildId) {
846
- return await rest.get(rest.routes.interactions.commands.guilds.one(rest.applicationId, guildId, commandId));
847
- },
848
- async getGuildApplicationCommands (guildId) {
849
- return await rest.get(rest.routes.interactions.commands.guilds.all(rest.applicationId, guildId));
850
- },
851
- async getGuildPreview (guildId) {
852
- return await rest.get(rest.routes.guilds.preview(guildId));
853
- },
854
- async getGuildTemplate (templateCode) {
855
- return await rest.get(rest.routes.guilds.templates.code(templateCode));
856
- },
857
- async getGuildTemplates (guildId) {
858
- return await rest.get(rest.routes.guilds.templates.all(guildId));
859
- },
860
- async getGuildWebhooks (guildId) {
861
- return await rest.get(rest.routes.guilds.webhooks(guildId));
862
- },
863
- async getIntegrations (guildId) {
864
- return await rest.get(rest.routes.guilds.integrations(guildId));
865
- },
866
- async getInvite (inviteCode, options) {
867
- return await rest.get(rest.routes.guilds.invite(inviteCode, options));
868
- },
869
- async getInvites (guildId) {
870
- return await rest.get(rest.routes.guilds.invites(guildId));
871
- },
872
- async getMessage (channelId, messageId) {
873
- return await rest.get(rest.routes.channels.message(channelId, messageId));
874
- },
875
- async getMessages (channelId, options) {
876
- return await rest.get(rest.routes.channels.messages(channelId, options));
877
- },
878
- async getNitroStickerPacks () {
879
- return await rest.get(rest.routes.nitroStickerPacks());
880
- },
881
- async getOriginalInteractionResponse (token) {
882
- return await rest.get(rest.routes.interactions.responses.original(rest.applicationId, token), {
883
- unauthorized: true
884
- });
885
- },
886
- async getPinnedMessages (channelId) {
887
- return await rest.get(rest.routes.channels.pins(channelId));
888
- },
889
- async getPrivateArchivedThreads (channelId, options) {
890
- return await rest.get(rest.routes.channels.threads.private(channelId, options));
891
- },
892
- async getPrivateJoinedArchivedThreads (channelId, options) {
893
- return await rest.get(rest.routes.channels.threads.joined(channelId, options));
894
- },
895
- async getPruneCount (guildId, options) {
896
- return await rest.get(rest.routes.guilds.prune(guildId, options));
897
- },
898
- async getPublicArchivedThreads (channelId, options) {
899
- return await rest.get(rest.routes.channels.threads.public(channelId, options));
900
- },
901
- async getRoles (guildId) {
902
- return await rest.get(rest.routes.guilds.roles.all(guildId));
903
- },
904
- async getScheduledEvent (guildId, eventId, options) {
905
- return await rest.get(rest.routes.guilds.events.event(guildId, eventId, options?.withUserCount));
906
- },
907
- async getScheduledEvents (guildId, options) {
908
- return await rest.get(rest.routes.guilds.events.events(guildId, options?.withUserCount));
909
- },
910
- async getScheduledEventUsers (guildId, eventId, options) {
911
- return await rest.get(rest.routes.guilds.events.users(guildId, eventId, options));
912
- },
913
- async getSessionInfo () {
914
- return await rest.getGatewayBot();
915
- },
916
- async getStageInstance (channelId) {
917
- return await rest.get(rest.routes.channels.stage(channelId));
918
- },
919
- async getSticker (stickerId) {
920
- return await rest.get(rest.routes.sticker(stickerId));
921
- },
922
- async getGuildSticker (guildId, stickerId) {
923
- return await rest.get(rest.routes.guilds.sticker(guildId, stickerId));
924
- },
925
- async getGuildStickers (guildId) {
926
- return await rest.get(rest.routes.guilds.stickers(guildId));
927
- },
928
- async getThreadMember (channelId, userId) {
929
- return await rest.get(rest.routes.channels.threads.user(channelId, userId));
930
- },
931
- async getThreadMembers (channelId) {
932
- return await rest.get(rest.routes.channels.threads.members(channelId));
933
- },
934
- async getReactions (channelId, messageId, reaction, options) {
935
- return await rest.get(rest.routes.channels.reactions.message(channelId, messageId, reaction, options));
936
- },
937
- async getUser (id) {
938
- return await rest.get(rest.routes.user(id));
939
- },
940
- async getVanityUrl (guildId) {
941
- return await rest.get(rest.routes.guilds.vanity(guildId));
942
- },
943
- async getVoiceRegions (guildId) {
944
- return await rest.get(rest.routes.guilds.regions(guildId));
945
- },
946
- async getWebhook (webhookId) {
947
- return await rest.get(rest.routes.webhooks.id(webhookId));
948
- },
949
- async getWebhookMessage (webhookId, token, messageId, options) {
950
- return await rest.get(rest.routes.webhooks.message(webhookId, token, messageId, options));
951
- },
952
- async getWebhookWithToken (webhookId, token) {
953
- return await rest.get(rest.routes.webhooks.webhook(webhookId, token));
954
- },
955
- async getWelcomeScreen (guildId) {
956
- return await rest.get(rest.routes.guilds.welcome(guildId));
957
- },
958
- async getWidget (guildId) {
959
- return await rest.get(rest.routes.guilds.widgetJson(guildId));
960
- },
961
- async getWidgetSettings (guildId) {
962
- return await rest.get(rest.routes.guilds.widget(guildId));
963
- },
964
- async joinThread (channelId) {
965
- await rest.put(rest.routes.channels.threads.me(channelId));
966
- },
967
- async leaveGuild (guildId) {
968
- await rest.delete(rest.routes.guilds.leave(guildId));
969
- },
970
- async leaveThread (channelId) {
971
- await rest.delete(rest.routes.channels.threads.me(channelId));
972
- },
973
- async publishMessage (channelId, messageId) {
974
- return await rest.post(rest.routes.channels.crosspost(channelId, messageId));
975
- },
976
- async removeRole (guildId, userId, roleId, reason) {
977
- await rest.delete(rest.routes.guilds.roles.member(guildId, userId, roleId), {
978
- reason
979
- });
980
- },
981
- async removeThreadMember (channelId, userId) {
982
- await rest.delete(rest.routes.channels.threads.user(channelId, userId));
983
- },
984
- async sendFollowupMessage (token, options) {
985
- return await rest.post(rest.routes.webhooks.webhook(rest.applicationId, token), {
986
- body: options,
987
- files: options.files,
988
- unauthorized: true
989
- });
990
- },
991
- async sendInteractionResponse (interactionId, token, options) {
992
- return await rest.post(rest.routes.interactions.responses.callback(interactionId, token), {
993
- body: options,
994
- files: options.data?.files,
995
- runThroughQueue: false,
996
- unauthorized: true
997
- });
998
- },
999
- async sendMessage (channelId, body) {
1000
- return await rest.post(rest.routes.channels.messages(channelId), {
1001
- body,
1002
- files: body.files
1003
- });
1004
- },
1005
- async startThreadWithMessage (channelId, messageId, body, reason) {
1006
- return await rest.post(rest.routes.channels.threads.message(channelId, messageId), {
1007
- body,
1008
- reason
1009
- });
1010
- },
1011
- async startThreadWithoutMessage (channelId, body, reason) {
1012
- return await rest.post(rest.routes.channels.threads.all(channelId), {
1013
- body,
1014
- reason
1015
- });
1016
- },
1017
- async syncGuildTemplate (guildId) {
1018
- return await rest.put(rest.routes.guilds.templates.all(guildId));
1019
- },
1020
- async banMember (guildId, userId, body, reason) {
1021
- await rest.put(rest.routes.guilds.members.ban(guildId, userId), {
1022
- body,
1023
- reason
1024
- });
1025
- },
1026
- async editBotMember (guildId, body, reason) {
1027
- return await rest.patch(rest.routes.guilds.members.bot(guildId), {
1028
- body,
1029
- reason
1030
- });
1031
- },
1032
- async editMember (guildId, userId, body, reason) {
1033
- return await rest.patch(rest.routes.guilds.members.member(guildId, userId), {
1034
- body,
1035
- reason
1036
- });
1037
- },
1038
- async getMember (guildId, userId) {
1039
- return await rest.get(rest.routes.guilds.members.member(guildId, userId));
1040
- },
1041
- async getMembers (guildId, options) {
1042
- return await rest.get(rest.routes.guilds.members.members(guildId, options));
1043
- },
1044
- async kickMember (guildId, userId, reason) {
1045
- await rest.delete(rest.routes.guilds.members.member(guildId, userId), {
1046
- reason
1047
- });
1048
- },
1049
- async pinMessage (channelId, messageId, reason) {
1050
- await rest.put(rest.routes.channels.pin(channelId, messageId), {
1051
- reason
1052
- });
1053
- },
1054
- async pruneMembers (guildId, body, reason) {
1055
- return await rest.post(rest.routes.guilds.members.prune(guildId), {
1056
- body,
1057
- reason
1058
- });
1059
- },
1060
- async searchMembers (guildId, query, options) {
1061
- return await rest.get(rest.routes.guilds.members.search(guildId, query, options));
1062
- },
1063
- async unbanMember (guildId, userId, reason) {
1064
- await rest.delete(rest.routes.guilds.members.ban(guildId, userId), {
1065
- reason
1066
- });
1067
- },
1068
- async unpinMessage (channelId, messageId, reason) {
1069
- await rest.delete(rest.routes.channels.pin(channelId, messageId), {
1070
- reason
1071
- });
1072
- },
1073
- async triggerTypingIndicator (channelId) {
1074
- await rest.post(rest.routes.channels.typing(channelId));
1075
- },
1076
- async upsertGlobalApplicationCommands (body) {
1077
- return await rest.put(rest.routes.interactions.commands.commands(rest.applicationId), {
1078
- body
1079
- });
1080
- },
1081
- async upsertGuildApplicationCommands (guildId, body) {
1082
- return await rest.put(rest.routes.interactions.commands.guilds.all(rest.applicationId, guildId), {
1083
- body
1084
- });
1085
- }
1086
- };
1087
- return rest;
1088
- }
1089
-
1090
- //# sourceMappingURL=manager.js.map