@discordjs/rest 0.6.0-dev.1655597378-3a77ce0 → 0.6.0-dev.1655640258-358c3f4

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/index.d.ts CHANGED
@@ -1,8 +1,765 @@
1
- export * from './lib/CDN';
2
- export * from './lib/errors/DiscordAPIError';
3
- export * from './lib/errors/HTTPError';
4
- export * from './lib/errors/RateLimitError';
5
- export * from './lib/RequestManager';
6
- export * from './lib/REST';
7
- export * from './lib/utils/constants';
8
- export { makeURLSearchParams, parseResponse } from './lib/utils/utils';
1
+ import { EventEmitter } from 'node:events';
2
+ import { Collection } from '@discordjs/collection';
3
+ import { Dispatcher, BodyInit, Agent, request } from 'undici';
4
+ import { URLSearchParams as URLSearchParams$1 } from 'node:url';
5
+
6
+ interface IHandler {
7
+ queueRequest: (routeId: RouteData, url: string, options: RequestOptions, requestData: HandlerRequestData) => Promise<Dispatcher.ResponseData>;
8
+ get inactive(): boolean;
9
+ readonly id: string;
10
+ }
11
+
12
+ /**
13
+ * Represents a file to be added to the request
14
+ */
15
+ interface RawFile {
16
+ /**
17
+ * The name of the file
18
+ */
19
+ name: string;
20
+ /**
21
+ * An explicit key to use for key of the formdata field for this file.
22
+ * When not provided, the index of the file in the files array is used in the form `files[${index}]`.
23
+ * If you wish to alter the placeholder snowflake, you must provide this property in the same form (`files[${placeholder}]`)
24
+ */
25
+ key?: string;
26
+ /**
27
+ * The actual data for the file
28
+ */
29
+ data: string | number | boolean | Buffer;
30
+ }
31
+ /**
32
+ * Represents possible data to be given to an endpoint
33
+ */
34
+ interface RequestData {
35
+ /**
36
+ * Whether to append JSON data to form data instead of `payload_json` when sending files
37
+ */
38
+ appendToFormData?: boolean;
39
+ /**
40
+ * If this request needs the `Authorization` header
41
+ * @default true
42
+ */
43
+ auth?: boolean;
44
+ /**
45
+ * The authorization prefix to use for this request, useful if you use this with bearer tokens
46
+ * @default 'Bot'
47
+ */
48
+ authPrefix?: 'Bot' | 'Bearer';
49
+ /**
50
+ * The body to send to this request.
51
+ * If providing as BodyInit, set `passThroughBody: true`
52
+ */
53
+ body?: BodyInit | unknown;
54
+ /**
55
+ * The {@link https://undici.nodejs.org/#/docs/api/Agent Agent} to use for the request.
56
+ */
57
+ dispatcher?: Agent;
58
+ /**
59
+ * Files to be attached to this request
60
+ */
61
+ files?: RawFile[] | undefined;
62
+ /**
63
+ * Additional headers to add to this request
64
+ */
65
+ headers?: Record<string, string>;
66
+ /**
67
+ * Whether to pass-through the body property directly to `fetch()`.
68
+ * <warn>This only applies when files is NOT present</warn>
69
+ */
70
+ passThroughBody?: boolean;
71
+ /**
72
+ * Query string parameters to append to the called endpoint
73
+ */
74
+ query?: URLSearchParams;
75
+ /**
76
+ * Reason to show in the audit logs
77
+ */
78
+ reason?: string;
79
+ /**
80
+ * If this request should be versioned
81
+ * @default true
82
+ */
83
+ versioned?: boolean;
84
+ }
85
+ /**
86
+ * Possible headers for an API call
87
+ */
88
+ interface RequestHeaders {
89
+ Authorization?: string;
90
+ 'User-Agent': string;
91
+ 'X-Audit-Log-Reason'?: string;
92
+ }
93
+ /**
94
+ * Possible API methods to be used when doing requests
95
+ */
96
+ declare const enum RequestMethod {
97
+ Delete = "DELETE",
98
+ Get = "GET",
99
+ Patch = "PATCH",
100
+ Post = "POST",
101
+ Put = "PUT"
102
+ }
103
+ declare type RouteLike = `/${string}`;
104
+ /**
105
+ * Internal request options
106
+ *
107
+ * @internal
108
+ */
109
+ interface InternalRequest extends RequestData {
110
+ method: RequestMethod;
111
+ fullRoute: RouteLike;
112
+ }
113
+ declare type HandlerRequestData = Pick<InternalRequest, 'files' | 'body' | 'auth'>;
114
+ /**
115
+ * Parsed route data for an endpoint
116
+ *
117
+ * @internal
118
+ */
119
+ interface RouteData {
120
+ majorParameter: string;
121
+ bucketRoute: string;
122
+ original: RouteLike;
123
+ }
124
+ /**
125
+ * Represents a hash and its associated fields
126
+ *
127
+ * @internal
128
+ */
129
+ interface HashData {
130
+ value: string;
131
+ lastAccess: number;
132
+ }
133
+ interface RequestManager {
134
+ on: (<K extends keyof RestEvents>(event: K, listener: (...args: RestEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof RestEvents>, listener: (...args: any[]) => void) => this);
135
+ once: (<K extends keyof RestEvents>(event: K, listener: (...args: RestEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof RestEvents>, listener: (...args: any[]) => void) => this);
136
+ emit: (<K extends keyof RestEvents>(event: K, ...args: RestEvents[K]) => boolean) & (<S extends string | symbol>(event: Exclude<S, keyof RestEvents>, ...args: any[]) => boolean);
137
+ off: (<K extends keyof RestEvents>(event: K, listener: (...args: RestEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof RestEvents>, listener: (...args: any[]) => void) => this);
138
+ removeAllListeners: (<K extends keyof RestEvents>(event?: K) => this) & (<S extends string | symbol>(event?: Exclude<S, keyof RestEvents>) => this);
139
+ }
140
+ /**
141
+ * Represents the class that manages handlers for endpoints
142
+ */
143
+ declare class RequestManager extends EventEmitter {
144
+ #private;
145
+ /**
146
+ * The {@link https://undici.nodejs.org/#/docs/api/Agent Agent} for all requests
147
+ * performed by this manager.
148
+ */
149
+ agent: Dispatcher | null;
150
+ /**
151
+ * The number of requests remaining in the global bucket
152
+ */
153
+ globalRemaining: number;
154
+ /**
155
+ * The promise used to wait out the global rate limit
156
+ */
157
+ globalDelay: Promise<void> | null;
158
+ /**
159
+ * The timestamp at which the global bucket resets
160
+ */
161
+ globalReset: number;
162
+ /**
163
+ * API bucket hashes that are cached from provided routes
164
+ */
165
+ readonly hashes: Collection<string, HashData>;
166
+ /**
167
+ * Request handlers created from the bucket hash and the major parameters
168
+ */
169
+ readonly handlers: Collection<string, IHandler>;
170
+ private hashTimer;
171
+ private handlerTimer;
172
+ readonly options: RESTOptions;
173
+ constructor(options: Partial<RESTOptions>);
174
+ private setupSweepers;
175
+ /**
176
+ * Sets the default agent to use for requests performed by this manager
177
+ * @param agent The agent to use
178
+ */
179
+ setAgent(agent: Dispatcher): this;
180
+ /**
181
+ * Sets the authorization token that should be used for requests
182
+ * @param token The authorization token to use
183
+ */
184
+ setToken(token: string): this;
185
+ /**
186
+ * Queues a request to be sent
187
+ * @param request All the information needed to make a request
188
+ * @returns The response from the api request
189
+ */
190
+ queueRequest(request: InternalRequest): Promise<Dispatcher.ResponseData>;
191
+ /**
192
+ * Creates a new rate limit handler from a hash, based on the hash and the major parameter
193
+ * @param hash The hash for the route
194
+ * @param majorParameter The major parameter for this handler
195
+ * @private
196
+ */
197
+ private createHandler;
198
+ /**
199
+ * Formats the request data to a usable format for fetch
200
+ * @param request The request data
201
+ */
202
+ private resolveRequest;
203
+ /**
204
+ * Stops the hash sweeping interval
205
+ */
206
+ clearHashSweeper(): void;
207
+ /**
208
+ * Stops the request handler sweeping interval
209
+ */
210
+ clearHandlerSweeper(): void;
211
+ /**
212
+ * Generates route data for an endpoint:method
213
+ * @param endpoint The raw endpoint to generalize
214
+ * @param method The HTTP method this endpoint is called without
215
+ * @private
216
+ */
217
+ private static generateRouteData;
218
+ }
219
+
220
+ /**
221
+ * Options to be passed when creating the REST instance
222
+ */
223
+ interface RESTOptions {
224
+ /**
225
+ * The agent to set globally
226
+ */
227
+ agent: Dispatcher;
228
+ /**
229
+ * The base api path, without version
230
+ * @default 'https://discord.com/api'
231
+ */
232
+ api: string;
233
+ /**
234
+ * The authorization prefix to use for requests, useful if you want to use
235
+ * bearer tokens
236
+ * @default 'Bot'
237
+ */
238
+ authPrefix: 'Bot' | 'Bearer';
239
+ /**
240
+ * The cdn path
241
+ * @default 'https://cdn.discordapp.com'
242
+ */
243
+ cdn: string;
244
+ /**
245
+ * Additional headers to send for all API requests
246
+ * @default {}
247
+ */
248
+ headers: Record<string, string>;
249
+ /**
250
+ * The number of invalid REST requests (those that return 401, 403, or 429) in a 10 minute window between emitted warnings (0 for no warnings).
251
+ * That is, if set to 500, warnings will be emitted at invalid request number 500, 1000, 1500, and so on.
252
+ * @default 0
253
+ */
254
+ invalidRequestWarningInterval: number;
255
+ /**
256
+ * How many requests to allow sending per second (Infinity for unlimited, 50 for the standard global limit used by Discord)
257
+ * @default 50
258
+ */
259
+ globalRequestsPerSecond: number;
260
+ /**
261
+ * The extra offset to add to rate limits in milliseconds
262
+ * @default 50
263
+ */
264
+ offset: number;
265
+ /**
266
+ * Determines how rate limiting and pre-emptive throttling should be handled.
267
+ * When an array of strings, each element is treated as a prefix for the request route
268
+ * (e.g. `/channels` to match any route starting with `/channels` such as `/channels/:id/messages`)
269
+ * for which to throw {@link RateLimitError}s. All other request routes will be queued normally
270
+ * @default null
271
+ */
272
+ rejectOnRateLimit: string[] | RateLimitQueueFilter | null;
273
+ /**
274
+ * The number of retries for errors with the 500 code, or errors
275
+ * that timeout
276
+ * @default 3
277
+ */
278
+ retries: number;
279
+ /**
280
+ * The time to wait in milliseconds before a request is aborted
281
+ * @default 15_000
282
+ */
283
+ timeout: number;
284
+ /**
285
+ * Extra information to add to the user agent
286
+ * @default `Node.js ${process.version}`
287
+ */
288
+ userAgentAppendix: string;
289
+ /**
290
+ * The version of the API to use
291
+ * @default '10'
292
+ */
293
+ version: string;
294
+ /**
295
+ * The amount of time in milliseconds that passes between each hash sweep. (defaults to 4h)
296
+ * @default 14_400_000
297
+ */
298
+ hashSweepInterval: number;
299
+ /**
300
+ * The maximum amount of time a hash can exist in milliseconds without being hit with a request (defaults to 24h)
301
+ * @default 86_400_000
302
+ */
303
+ hashLifetime: number;
304
+ /**
305
+ * The amount of time in milliseconds that passes between each hash sweep. (defaults to 1h)
306
+ * @default 3_600_000
307
+ */
308
+ handlerSweepInterval: number;
309
+ }
310
+ /**
311
+ * Data emitted on `RESTEvents.RateLimited`
312
+ */
313
+ interface RateLimitData {
314
+ /**
315
+ * The time, in milliseconds, until the request-lock is reset
316
+ */
317
+ timeToReset: number;
318
+ /**
319
+ * The amount of requests we can perform before locking requests
320
+ */
321
+ limit: number;
322
+ /**
323
+ * The HTTP method being performed
324
+ */
325
+ method: string;
326
+ /**
327
+ * The bucket hash for this request
328
+ */
329
+ hash: string;
330
+ /**
331
+ * The full URL for this request
332
+ */
333
+ url: string;
334
+ /**
335
+ * The route being hit in this request
336
+ */
337
+ route: string;
338
+ /**
339
+ * The major parameter of the route
340
+ *
341
+ * For example, in `/channels/x`, this will be `x`.
342
+ * If there is no major parameter (e.g: `/bot/gateway`) this will be `global`.
343
+ */
344
+ majorParameter: string;
345
+ /**
346
+ * Whether the rate limit that was reached was the global limit
347
+ */
348
+ global: boolean;
349
+ }
350
+ /**
351
+ * A function that determines whether the rate limit hit should throw an Error
352
+ */
353
+ declare type RateLimitQueueFilter = (rateLimitData: RateLimitData) => boolean | Promise<boolean>;
354
+ interface APIRequest {
355
+ /**
356
+ * The HTTP method used in this request
357
+ */
358
+ method: string;
359
+ /**
360
+ * The full path used to make the request
361
+ */
362
+ path: RouteLike;
363
+ /**
364
+ * The API route identifying the ratelimit for this request
365
+ */
366
+ route: string;
367
+ /**
368
+ * Additional HTTP options for this request
369
+ */
370
+ options: RequestOptions;
371
+ /**
372
+ * The data that was used to form the body of this request
373
+ */
374
+ data: HandlerRequestData;
375
+ /**
376
+ * The number of times this request has been attempted
377
+ */
378
+ retries: number;
379
+ }
380
+ interface InvalidRequestWarningData {
381
+ /**
382
+ * Number of invalid requests that have been made in the window
383
+ */
384
+ count: number;
385
+ /**
386
+ * Time in milliseconds remaining before the count resets
387
+ */
388
+ remainingTime: number;
389
+ }
390
+ interface RestEvents {
391
+ invalidRequestWarning: [invalidRequestInfo: InvalidRequestWarningData];
392
+ restDebug: [info: string];
393
+ rateLimited: [rateLimitInfo: RateLimitData];
394
+ response: [request: APIRequest, response: Dispatcher.ResponseData];
395
+ newListener: [name: string, listener: (...args: any) => void];
396
+ removeListener: [name: string, listener: (...args: any) => void];
397
+ hashSweep: [sweptHashes: Collection<string, HashData>];
398
+ handlerSweep: [sweptHandlers: Collection<string, IHandler>];
399
+ }
400
+ declare type RequestOptions = Exclude<Parameters<typeof request>[1], undefined>;
401
+ interface REST {
402
+ on: (<K extends keyof RestEvents>(event: K, listener: (...args: RestEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof RestEvents>, listener: (...args: any[]) => void) => this);
403
+ once: (<K extends keyof RestEvents>(event: K, listener: (...args: RestEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof RestEvents>, listener: (...args: any[]) => void) => this);
404
+ emit: (<K extends keyof RestEvents>(event: K, ...args: RestEvents[K]) => boolean) & (<S extends string | symbol>(event: Exclude<S, keyof RestEvents>, ...args: any[]) => boolean);
405
+ off: (<K extends keyof RestEvents>(event: K, listener: (...args: RestEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof RestEvents>, listener: (...args: any[]) => void) => this);
406
+ removeAllListeners: (<K extends keyof RestEvents>(event?: K) => this) & (<S extends string | symbol>(event?: Exclude<S, keyof RestEvents>) => this);
407
+ }
408
+ declare class REST extends EventEmitter {
409
+ readonly cdn: CDN;
410
+ readonly requestManager: RequestManager;
411
+ constructor(options?: Partial<RESTOptions>);
412
+ /**
413
+ * Gets the agent set for this instance
414
+ */
415
+ getAgent(): Dispatcher | null;
416
+ /**
417
+ * Sets the default agent to use for requests performed by this instance
418
+ * @param agent Sets the agent to use
419
+ */
420
+ setAgent(agent: Dispatcher): this;
421
+ /**
422
+ * Sets the authorization token that should be used for requests
423
+ * @param token The authorization token to use
424
+ */
425
+ setToken(token: string): this;
426
+ /**
427
+ * Runs a get request from the api
428
+ * @param fullRoute The full route to query
429
+ * @param options Optional request options
430
+ */
431
+ get(fullRoute: RouteLike, options?: RequestData): Promise<unknown>;
432
+ /**
433
+ * Runs a delete request from the api
434
+ * @param fullRoute The full route to query
435
+ * @param options Optional request options
436
+ */
437
+ delete(fullRoute: RouteLike, options?: RequestData): Promise<unknown>;
438
+ /**
439
+ * Runs a post request from the api
440
+ * @param fullRoute The full route to query
441
+ * @param options Optional request options
442
+ */
443
+ post(fullRoute: RouteLike, options?: RequestData): Promise<unknown>;
444
+ /**
445
+ * Runs a put request from the api
446
+ * @param fullRoute The full route to query
447
+ * @param options Optional request options
448
+ */
449
+ put(fullRoute: RouteLike, options?: RequestData): Promise<unknown>;
450
+ /**
451
+ * Runs a patch request from the api
452
+ * @param fullRoute The full route to query
453
+ * @param options Optional request options
454
+ */
455
+ patch(fullRoute: RouteLike, options?: RequestData): Promise<unknown>;
456
+ /**
457
+ * Runs a request from the api
458
+ * @param options Request options
459
+ */
460
+ request(options: InternalRequest): Promise<unknown>;
461
+ /**
462
+ * Runs a request from the API, yielding the raw Response object
463
+ * @param options Request options
464
+ */
465
+ raw(options: InternalRequest): Promise<Dispatcher.ResponseData>;
466
+ }
467
+
468
+ declare const DefaultUserAgent: string;
469
+ declare const DefaultRestOptions: Required<RESTOptions>;
470
+ /**
471
+ * The events that the REST manager emits
472
+ */
473
+ declare const enum RESTEvents {
474
+ Debug = "restDebug",
475
+ InvalidRequestWarning = "invalidRequestWarning",
476
+ RateLimited = "rateLimited",
477
+ Response = "response",
478
+ HashSweep = "hashSweep",
479
+ HandlerSweep = "handlerSweep"
480
+ }
481
+ declare const ALLOWED_EXTENSIONS: readonly ["webp", "png", "jpg", "jpeg", "gif"];
482
+ declare const ALLOWED_STICKER_EXTENSIONS: readonly ["png", "json"];
483
+ declare const ALLOWED_SIZES: readonly [16, 32, 64, 128, 256, 512, 1024, 2048, 4096];
484
+ declare type ImageExtension = typeof ALLOWED_EXTENSIONS[number];
485
+ declare type StickerExtension = typeof ALLOWED_STICKER_EXTENSIONS[number];
486
+ declare type ImageSize = typeof ALLOWED_SIZES[number];
487
+
488
+ /**
489
+ * The options used for image URLs
490
+ */
491
+ interface BaseImageURLOptions {
492
+ /**
493
+ * The extension to use for the image URL
494
+ * @default 'webp'
495
+ */
496
+ extension?: ImageExtension;
497
+ /**
498
+ * The size specified in the image URL
499
+ */
500
+ size?: ImageSize;
501
+ }
502
+ /**
503
+ * The options used for image URLs with animated content
504
+ */
505
+ interface ImageURLOptions extends BaseImageURLOptions {
506
+ /**
507
+ * Whether or not to prefer the static version of an image asset.
508
+ */
509
+ forceStatic?: boolean;
510
+ }
511
+ /**
512
+ * The options to use when making a CDN URL
513
+ */
514
+ interface MakeURLOptions {
515
+ /**
516
+ * The extension to use for the image URL
517
+ * @default 'webp'
518
+ */
519
+ extension?: string | undefined;
520
+ /**
521
+ * The size specified in the image URL
522
+ */
523
+ size?: ImageSize;
524
+ /**
525
+ * The allowed extensions that can be used
526
+ */
527
+ allowedExtensions?: ReadonlyArray<string>;
528
+ }
529
+ /**
530
+ * The CDN link builder
531
+ */
532
+ declare class CDN {
533
+ private readonly base;
534
+ constructor(base?: string);
535
+ /**
536
+ * Generates an app asset URL for a client's asset.
537
+ * @param clientId The client id that has the asset
538
+ * @param assetHash The hash provided by Discord for this asset
539
+ * @param options Optional options for the asset
540
+ */
541
+ appAsset(clientId: string, assetHash: string, options?: Readonly<BaseImageURLOptions>): string;
542
+ /**
543
+ * Generates an app icon URL for a client's icon.
544
+ * @param clientId The client id that has the icon
545
+ * @param iconHash The hash provided by Discord for this icon
546
+ * @param options Optional options for the icon
547
+ */
548
+ appIcon(clientId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string;
549
+ /**
550
+ * Generates an avatar URL, e.g. for a user or a webhook.
551
+ * @param id The id that has the icon
552
+ * @param avatarHash The hash provided by Discord for this avatar
553
+ * @param options Optional options for the avatar
554
+ */
555
+ avatar(id: string, avatarHash: string, options?: Readonly<ImageURLOptions>): string;
556
+ /**
557
+ * Generates a banner URL, e.g. for a user or a guild.
558
+ * @param id The id that has the banner splash
559
+ * @param bannerHash The hash provided by Discord for this banner
560
+ * @param options Optional options for the banner
561
+ */
562
+ banner(id: string, bannerHash: string, options?: Readonly<ImageURLOptions>): string;
563
+ /**
564
+ * Generates an icon URL for a channel, e.g. a group DM.
565
+ * @param channelId The channel id that has the icon
566
+ * @param iconHash The hash provided by Discord for this channel
567
+ * @param options Optional options for the icon
568
+ */
569
+ channelIcon(channelId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string;
570
+ /**
571
+ * Generates the default avatar URL for a discriminator.
572
+ * @param discriminator The discriminator modulo 5
573
+ */
574
+ defaultAvatar(discriminator: number): string;
575
+ /**
576
+ * Generates a discovery splash URL for a guild's discovery splash.
577
+ * @param guildId The guild id that has the discovery splash
578
+ * @param splashHash The hash provided by Discord for this splash
579
+ * @param options Optional options for the splash
580
+ */
581
+ discoverySplash(guildId: string, splashHash: string, options?: Readonly<BaseImageURLOptions>): string;
582
+ /**
583
+ * Generates an emoji's URL for an emoji.
584
+ * @param emojiId The emoji id
585
+ * @param extension The extension of the emoji
586
+ */
587
+ emoji(emojiId: string, extension?: ImageExtension): string;
588
+ /**
589
+ * Generates a guild member avatar URL.
590
+ * @param guildId The id of the guild
591
+ * @param userId The id of the user
592
+ * @param avatarHash The hash provided by Discord for this avatar
593
+ * @param options Optional options for the avatar
594
+ */
595
+ guildMemberAvatar(guildId: string, userId: string, avatarHash: string, options?: Readonly<ImageURLOptions>): string;
596
+ /**
597
+ * Generates a guild member banner URL.
598
+ * @param guildId The id of the guild
599
+ * @param userId The id of the user
600
+ * @param bannerHash The hash provided by Discord for this banner
601
+ * @param options Optional options for the banner
602
+ */
603
+ guildMemberBanner(guildId: string, userId: string, bannerHash: string, options?: Readonly<ImageURLOptions>): string;
604
+ /**
605
+ * Generates an icon URL, e.g. for a guild.
606
+ * @param id The id that has the icon splash
607
+ * @param iconHash The hash provided by Discord for this icon
608
+ * @param options Optional options for the icon
609
+ */
610
+ icon(id: string, iconHash: string, options?: Readonly<ImageURLOptions>): string;
611
+ /**
612
+ * Generates a URL for the icon of a role
613
+ * @param roleId The id of the role that has the icon
614
+ * @param roleIconHash The hash provided by Discord for this role icon
615
+ * @param options Optional options for the role icon
616
+ */
617
+ roleIcon(roleId: string, roleIconHash: string, options?: Readonly<BaseImageURLOptions>): string;
618
+ /**
619
+ * Generates a guild invite splash URL for a guild's invite splash.
620
+ * @param guildId The guild id that has the invite splash
621
+ * @param splashHash The hash provided by Discord for this splash
622
+ * @param options Optional options for the splash
623
+ */
624
+ splash(guildId: string, splashHash: string, options?: Readonly<BaseImageURLOptions>): string;
625
+ /**
626
+ * Generates a sticker URL.
627
+ * @param stickerId The sticker id
628
+ * @param extension The extension of the sticker
629
+ */
630
+ sticker(stickerId: string, extension?: StickerExtension): string;
631
+ /**
632
+ * Generates a sticker pack banner URL.
633
+ * @param bannerId The banner id
634
+ * @param options Optional options for the banner
635
+ */
636
+ stickerPackBanner(bannerId: string, options?: Readonly<BaseImageURLOptions>): string;
637
+ /**
638
+ * Generates a team icon URL for a team's icon.
639
+ * @param teamId The team id that has the icon
640
+ * @param iconHash The hash provided by Discord for this icon
641
+ * @param options Optional options for the icon
642
+ */
643
+ teamIcon(teamId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string;
644
+ /**
645
+ * Generates a cover image for a guild scheduled event.
646
+ * @param scheduledEventId The scheduled event id
647
+ * @param coverHash The hash provided by discord for this cover image
648
+ * @param options Optional options for the cover image
649
+ */
650
+ guildScheduledEventCover(scheduledEventId: string, coverHash: string, options?: Readonly<BaseImageURLOptions>): string;
651
+ /**
652
+ * Constructs the URL for the resource, checking whether or not `hash` starts with `a_` if `dynamic` is set to `true`.
653
+ * @param route The base cdn route
654
+ * @param hash The hash provided by Discord for this icon
655
+ * @param options Optional options for the link
656
+ */
657
+ private dynamicMakeURL;
658
+ /**
659
+ * Constructs the URL for the resource
660
+ * @param route The base cdn route
661
+ * @param options The extension/size options for the link
662
+ */
663
+ private makeURL;
664
+ }
665
+
666
+ interface DiscordErrorFieldInformation {
667
+ code: string;
668
+ message: string;
669
+ }
670
+ interface DiscordErrorGroupWrapper {
671
+ _errors: DiscordError[];
672
+ }
673
+ declare type DiscordError = DiscordErrorGroupWrapper | DiscordErrorFieldInformation | {
674
+ [k: string]: DiscordError;
675
+ } | string;
676
+ interface DiscordErrorData {
677
+ code: number;
678
+ message: string;
679
+ errors?: DiscordError;
680
+ }
681
+ interface OAuthErrorData {
682
+ error: string;
683
+ error_description?: string;
684
+ }
685
+ interface RequestBody {
686
+ files: RawFile[] | undefined;
687
+ json: unknown | undefined;
688
+ }
689
+ /**
690
+ * Represents an API error returned by Discord
691
+ * @extends Error
692
+ */
693
+ declare class DiscordAPIError extends Error {
694
+ rawError: DiscordErrorData | OAuthErrorData;
695
+ code: number | string;
696
+ status: number;
697
+ method: string;
698
+ url: string;
699
+ requestBody: RequestBody;
700
+ /**
701
+ * @param rawError The error reported by Discord
702
+ * @param code The error code reported by Discord
703
+ * @param status The status code of the response
704
+ * @param method The method of the request that erred
705
+ * @param url The url of the request that erred
706
+ * @param bodyData The unparsed data for the request that errored
707
+ */
708
+ constructor(rawError: DiscordErrorData | OAuthErrorData, code: number | string, status: number, method: string, url: string, bodyData: Pick<InternalRequest, 'files' | 'body'>);
709
+ /**
710
+ * The name of the error
711
+ */
712
+ get name(): string;
713
+ private static getMessage;
714
+ private static flattenDiscordError;
715
+ }
716
+
717
+ /**
718
+ * Represents a HTTP error
719
+ */
720
+ declare class HTTPError extends Error {
721
+ name: string;
722
+ status: number;
723
+ method: string;
724
+ url: string;
725
+ requestBody: RequestBody;
726
+ /**
727
+ * @param name The name of the error
728
+ * @param status The status code of the response
729
+ * @param method The method of the request that erred
730
+ * @param url The url of the request that erred
731
+ * @param bodyData The unparsed data for the request that errored
732
+ */
733
+ constructor(name: string, status: number, method: string, url: string, bodyData: Pick<InternalRequest, 'files' | 'body'>);
734
+ }
735
+
736
+ declare class RateLimitError extends Error implements RateLimitData {
737
+ timeToReset: number;
738
+ limit: number;
739
+ method: string;
740
+ hash: string;
741
+ url: string;
742
+ route: string;
743
+ majorParameter: string;
744
+ global: boolean;
745
+ constructor({ timeToReset, limit, method, hash, url, route, majorParameter, global }: RateLimitData);
746
+ /**
747
+ * The name of the error
748
+ */
749
+ get name(): string;
750
+ }
751
+
752
+ /**
753
+ * Creates and populates an URLSearchParams instance from an object, stripping
754
+ * out null and undefined values, while also coercing non-strings to strings.
755
+ * @param options The options to use
756
+ * @returns A populated URLSearchParams instance
757
+ */
758
+ declare function makeURLSearchParams(options?: Record<string, unknown>): URLSearchParams$1;
759
+ /**
760
+ * Converts the response to usable data
761
+ * @param res The fetch response
762
+ */
763
+ declare function parseResponse(res: Dispatcher.ResponseData): Promise<unknown>;
764
+
765
+ export { ALLOWED_EXTENSIONS, ALLOWED_SIZES, ALLOWED_STICKER_EXTENSIONS, APIRequest, BaseImageURLOptions, CDN, DefaultRestOptions, DefaultUserAgent, DiscordAPIError, DiscordErrorData, HTTPError, HandlerRequestData, HashData, ImageExtension, ImageSize, ImageURLOptions, InternalRequest, InvalidRequestWarningData, MakeURLOptions, OAuthErrorData, REST, RESTEvents, RESTOptions, RateLimitData, RateLimitError, RateLimitQueueFilter, RawFile, RequestBody, RequestData, RequestHeaders, RequestManager, RequestMethod, RequestOptions, RestEvents, RouteData, RouteLike, StickerExtension, makeURLSearchParams, parseResponse };