@ovencord/discord.js 14.16.14 → 14.16.15-dev.1

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 (57) hide show
  1. package/package.json +10 -11
  2. package/src/client/Client.ts +102 -114
  3. package/src/client/actions/Action.ts +27 -23
  4. package/src/client/actions/ChannelCreate.ts +2 -2
  5. package/src/client/actions/ChannelDelete.ts +1 -1
  6. package/src/client/actions/ChannelUpdate.ts +2 -2
  7. package/src/client/actions/GuildChannelsPositionUpdate.ts +1 -1
  8. package/src/client/actions/GuildEmojiCreate.ts +1 -1
  9. package/src/client/actions/GuildEmojiDelete.ts +1 -1
  10. package/src/client/actions/GuildEmojiUpdate.ts +1 -1
  11. package/src/client/actions/GuildEmojisUpdate.ts +1 -1
  12. package/src/client/actions/GuildMemberRemove.ts +1 -1
  13. package/src/client/actions/GuildMemberUpdate.ts +1 -1
  14. package/src/client/actions/GuildRoleCreate.ts +1 -1
  15. package/src/client/actions/GuildRoleDelete.ts +1 -1
  16. package/src/client/actions/GuildRolesPositionUpdate.ts +1 -1
  17. package/src/client/actions/GuildScheduledEventDelete.ts +1 -1
  18. package/src/client/actions/GuildScheduledEventUserAdd.ts +1 -1
  19. package/src/client/actions/GuildScheduledEventUserRemove.ts +1 -1
  20. package/src/client/actions/GuildSoundboardSoundDelete.ts +1 -1
  21. package/src/client/actions/GuildStickerCreate.ts +1 -1
  22. package/src/client/actions/GuildStickerDelete.ts +1 -1
  23. package/src/client/actions/GuildStickerUpdate.ts +1 -1
  24. package/src/client/actions/GuildStickersUpdate.ts +1 -1
  25. package/src/client/actions/GuildUpdate.ts +1 -1
  26. package/src/client/actions/InteractionCreate.ts +1 -1
  27. package/src/client/actions/MessageCreate.ts +2 -2
  28. package/src/client/actions/MessageDelete.ts +2 -2
  29. package/src/client/actions/MessageDeleteBulk.ts +1 -1
  30. package/src/client/actions/MessagePollVoteAdd.ts +2 -2
  31. package/src/client/actions/MessagePollVoteRemove.ts +2 -2
  32. package/src/client/actions/MessageReactionAdd.ts +2 -2
  33. package/src/client/actions/MessageReactionRemove.ts +2 -2
  34. package/src/client/actions/MessageReactionRemoveAll.ts +1 -1
  35. package/src/client/actions/MessageReactionRemoveEmoji.ts +1 -1
  36. package/src/client/actions/MessageUpdate.ts +1 -1
  37. package/src/client/actions/StageInstanceCreate.ts +1 -1
  38. package/src/client/actions/StageInstanceDelete.ts +1 -1
  39. package/src/client/actions/StageInstanceUpdate.ts +1 -1
  40. package/src/client/actions/ThreadCreate.ts +1 -1
  41. package/src/client/actions/ThreadMembersUpdate.ts +1 -1
  42. package/src/client/actions/TypingStart.ts +1 -1
  43. package/src/client/actions/UserUpdate.ts +1 -1
  44. package/src/client/websocket/handlers/RATE_LIMITED.ts +1 -1
  45. package/src/managers/ApplicationEmojiManager.ts +11 -11
  46. package/src/managers/PresenceManager.ts +0 -1
  47. package/src/managers/UserManager.ts +0 -1
  48. package/src/sharding/Shard.ts +38 -37
  49. package/src/sharding/ShardClientUtil.ts +18 -19
  50. package/src/sharding/ShardingManager.ts +7 -7
  51. package/src/structures/AnonymousGuild.ts +0 -1
  52. package/src/structures/BaseGuild.ts +0 -1
  53. package/src/structures/Guild.ts +0 -1
  54. package/src/structures/interfaces/Collector.ts +1 -1
  55. package/src/util/AsyncEventEmitter.ts +150 -0
  56. package/src/util/Partials.ts +1 -1
  57. package/src/util/Status.ts +5 -15
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@ovencord/discord.js",
4
- "version": "14.16.14",
4
+ "version": "14.16.15-dev.1",
5
5
  "description": "A powerful library for interacting with the Discord API",
6
6
  "scripts": {
7
7
  "test": "bun test",
@@ -39,20 +39,19 @@
39
39
  "dependencies": {
40
40
  "tslib": "^2.6.2",
41
41
  "@sapphire/snowflake": "3.5.5",
42
- "@vladfrangu/async_event_emitter": "^2.4.7",
43
42
  "discord-api-types": "^0.38.36",
44
43
  "fast-deep-equal": "3.1.3",
45
- "@ovencord/builders": "^1.11.4",
46
- "@ovencord/collection": "^2.1.1",
47
- "@ovencord/formatters": "^0.6.1",
48
- "@ovencord/rest": "^2.5.0",
49
- "@ovencord/util": "^1.1.1",
50
- "@ovencord/ws": "^2.0.2"
44
+ "@ovencord/builders": "1.11.5",
45
+ "@ovencord/collection": "2.1.1",
46
+ "@ovencord/formatters": "0.6.1",
47
+ "@ovencord/rest": "2.5.1",
48
+ "@ovencord/util": "1.1.1",
49
+ "@ovencord/ws": "2.0.2"
51
50
  },
52
51
  "devDependencies": {
53
- "@ovencord/api-extractor": "^7.52.7",
54
- "@ovencord/docgen": "^0.12.1",
55
- "@ovencord/scripts": "^0.1.0",
52
+ "@ovencord/api-extractor": "7.52.7",
53
+ "@ovencord/docgen": "0.12.1",
54
+ "@ovencord/scripts": "0.1.0",
56
55
  "@favware/cliff-jumper": "^6.0.0",
57
56
  "@types/bun": "latest",
58
57
  "cross-env": "^10.1.0",
@@ -1,14 +1,12 @@
1
- import process from 'node:process';
2
1
  import { workerData } from 'node:worker_threads';
3
- import { clearTimeout, setImmediate, setTimeout } from 'node:timers';
4
2
  import { Collection } from '@ovencord/collection';
5
3
  import { REST, RESTEvents, makeURLSearchParams } from '@ovencord/rest';
6
4
  import { WebSocketManager, WebSocketShardEvents, WebSocketShardStatus } from '@ovencord/ws';
7
- import { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';
8
- import { GatewayDispatchEvents, GatewayIntentBits, OAuth2Scopes, Routes } from 'discord-api-types/v10';
5
+ import { AsyncEventEmitter } from '../util/AsyncEventEmitter.js';
6
+ import { GatewayDispatchEvents, GatewayIntentBits, OAuth2Scopes, Routes, type Snowflake } from 'discord-api-types/v10';
9
7
  import { DiscordjsError, DiscordjsTypeError, ErrorCodes } from '../errors/index.js';
10
8
  import { ChannelManager } from '../managers/ChannelManager.js';
11
- import { GuildManager } from '../managers/GuildManager.js';
9
+ import { GuildManager } from '../managers/GuildManager.js';
12
10
  import { UserManager } from '../managers/UserManager.js';
13
11
  import { ShardClientUtil } from '../sharding/ShardClientUtil.js';
14
12
  import { ClientPresence } from '../structures/ClientPresence.js';
@@ -25,13 +23,16 @@ import { Events } from '../util/Events.js';
25
23
  import { IntentsBitField } from '../util/IntentsBitField.js';
26
24
  import { createInvite } from '../util/Invites.js';
27
25
  import { Options } from '../util/Options.js';
28
- import { PermissionsBitField } from '../util/PermissionsBitField.js';
26
+ import { PermissionsBitField } from '../util/PermissionsBitField.js';
29
27
  import { Status } from '../util/Status.js';
30
28
  import { Sweepers } from '../util/Sweepers.js';
31
29
  import { flatten } from '../util/Util.js';
32
- import { ActionsManager } from './actions/ActionsManager.js';
33
- import { ClientVoiceManager } from './voice/ClientVoiceManager.js';
34
- import { PacketHandlers } from './websocket/handlers/index.js';
30
+
31
+ import { ActionsManager } from './actions/ActionsManager.js';
32
+ import { ClientVoiceManager } from './voice/ClientVoiceManager.js';
33
+ import { PacketHandlers } from './websocket/handlers/index.js';
34
+ import { ClientUser } from '../structures/ClientUser.js';
35
+ import { ClientApplication } from '../structures/ClientApplication.js';
35
36
 
36
37
  const WaitingForGuildEvents = [GatewayDispatchEvents.GuildCreate, GatewayDispatchEvents.GuildDelete];
37
38
  const BeforeReadyWhitelist = [
@@ -44,11 +45,44 @@ const BeforeReadyWhitelist = [
44
45
  GatewayDispatchEvents.GuildMemberRemove,
45
46
  ];
46
47
 
48
+ export type GuildResolvable = any;
49
+ export type PermissionResolvable = any;
50
+
47
51
  /**
48
52
  * The main hub for interacting with the Discord API, and the starting point for any bot.
49
53
  *
50
54
  * @extends {AsyncEventEmitter}
51
55
  */
56
+ export interface WebhookDeleteOptions {
57
+ /** Token of the webhook */
58
+ token?: string;
59
+ /** The reason for deleting the webhook */
60
+ reason?: string;
61
+ }
62
+
63
+ export interface ClientFetchInviteOptions {
64
+ /** Whether to include approximate member counts */
65
+ withCounts?: boolean;
66
+ /** The id of the guild scheduled event to include with the invite */
67
+ guildScheduledEventId?: string;
68
+ }
69
+
70
+ export interface StickerPackFetchOptions {
71
+ /** The id of the sticker pack to fetch */
72
+ packId?: string;
73
+ }
74
+
75
+ export interface InviteGenerationOptions {
76
+ /** Scopes that should be requested */
77
+ scopes: OAuth2Scopes[];
78
+ /** Permissions to request */
79
+ permissions?: PermissionResolvable;
80
+ /** Guild to preselect */
81
+ guild?: GuildResolvable;
82
+ /** Whether to disable the guild selection */
83
+ disableGuildSelect?: boolean;
84
+ }
85
+
52
86
  export class Client extends AsyncEventEmitter {
53
87
  public status: any;
54
88
  public readyTimeout: any;
@@ -69,12 +103,15 @@ export class Client extends AsyncEventEmitter {
69
103
  public lastPingTimestamps: Collection<number, number>;
70
104
  public readyTimestamp: number | null;
71
105
  public token: string | null;
106
+ public expectedGuilds: Set<string>;
107
+ public incomingPacketQueue: any[];
72
108
 
73
109
  /**
74
110
  * @param {any} options Options for the client
75
111
  */
76
112
  constructor(options: any) {
77
113
  super();
114
+ this.token = null;
78
115
 
79
116
  if (typeof options !== 'object' || options === null) {
80
117
  throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'options', 'object', true);
@@ -138,6 +175,18 @@ export class Client extends AsyncEventEmitter {
138
175
  */
139
176
  this.presence = new ClientPresence(this, this.options.ws.initialPresence ?? this.options.presence);
140
177
 
178
+ this.ws = new WebSocketManager(this as any);
179
+ this.actions = new ActionsManager(this);
180
+ this.voice = new ClientVoiceManager(this);
181
+ this.shard =
182
+ !process.env.SHARDING_MANAGER && !process.env.DISCORD_HYBRID_SHARDING
183
+ ? null
184
+ : ShardClientUtil.singleton(this, process.env.SHARDING_MANAGER_MODE as any);
185
+ this.users = new UserManager(this, undefined as any);
186
+ this.guilds = new GuildManager(this, undefined as any);
187
+ this.channels = new ChannelManager(this, undefined as any);
188
+ this.sweepers = new Sweepers(this, this.options.sweepers);
189
+
141
190
  this._validateOptions();
142
191
 
143
192
  /**
@@ -148,14 +197,7 @@ export class Client extends AsyncEventEmitter {
148
197
  */
149
198
  this.status = Status.Idle;
150
199
 
151
- /**
152
- * A set of guild ids this Client expects to receive
153
- *
154
- * @name Client#expectedGuilds
155
- * @type {Set<string>}
156
- * @private
157
- */
158
- Object.defineProperty(this, 'expectedGuilds', { value: new Set(), writable: true });
200
+ this.expectedGuilds = new Set();
159
201
 
160
202
  /**
161
203
  * The ready timeout
@@ -164,47 +206,9 @@ export class Client extends AsyncEventEmitter {
164
206
  * @type {?NodeJS.Timeout}
165
207
  * @private
166
208
  */
167
- Object.defineProperty(this, 'readyTimeout', { value: null, writable: true });
209
+ this.readyTimeout = null;
168
210
 
169
- /**
170
- * The action manager of the client
171
- *
172
- * @type {ActionsManager}
173
- * @private
174
- */
175
- this.actions = new ActionsManager(this);
176
211
 
177
- /**
178
- * The user manager of this client
179
- *
180
- * @type {UserManager}
181
- */
182
- this.users = new UserManager(this);
183
-
184
- /**
185
- * A manager of all the guilds the client is currently handling -
186
- * as long as sharding isn't being used, this will be *every* guild the bot is a member of
187
- *
188
- * @type {GuildManager}
189
- */
190
- this.guilds = new GuildManager(this);
191
-
192
- /**
193
- * All of the {@link BaseChannel}s that the client is currently handling -
194
- * as long as sharding isn't being used, this will be *every* channel in *every* guild the bot
195
- * is a member of. Note that DM channels will not be initially cached, and thus not be present
196
- * in the Manager without their explicit fetching or use.
197
- *
198
- * @type {ChannelManager}
199
- */
200
- this.channels = new ChannelManager(this);
201
-
202
- /**
203
- * The sweeping functions and their intervals used to periodically sweep caches
204
- *
205
- * @type {Sweepers}
206
- */
207
- this.sweepers = new Sweepers(this, this.options.sweepers);
208
212
 
209
213
  Object.defineProperty(this, 'token', { writable: true });
210
214
  if (!this.token && 'DISCORD_TOKEN' in process.env) {
@@ -215,7 +219,7 @@ export class Client extends AsyncEventEmitter {
215
219
  *
216
220
  * @type {?string}
217
221
  */
218
- this.token = process.env.DISCORD_TOKEN;
222
+ this.token = process.env.DISCORD_TOKEN ?? null;
219
223
  } else if (this.options.ws.token) {
220
224
  this.token = this.options.ws.token;
221
225
  } else {
@@ -295,7 +299,8 @@ export class Client extends AsyncEventEmitter {
295
299
  * @private
296
300
  * @name Client#incomingPacketQueue
297
301
  */
298
- Object.defineProperty(this, 'incomingPacketQueue', { value: [] });
302
+ this.readyTimestamp = null;
303
+ this.incomingPacketQueue = [];
299
304
 
300
305
  this._attachEvents();
301
306
  }
@@ -403,12 +408,12 @@ export class Client extends AsyncEventEmitter {
403
408
  * @private
404
409
  */
405
410
  _attachEvents() {
406
- this.ws.on(WebSocketShardEvents.Debug, (message, shardId) =>
411
+ this.ws.on(WebSocketShardEvents.Debug, (message: string, shardId: number) =>
407
412
  this.emit(Events.Debug, `[WS => ${typeof shardId === 'number' ? `Shard ${shardId}` : 'Manager'}] ${message}`),
408
413
  );
409
414
  this.ws.on(WebSocketShardEvents.Dispatch, this._handlePacket.bind(this));
410
415
 
411
- this.ws.on(WebSocketShardEvents.HeartbeatComplete, ({ heartbeatAt, latency }, shardId) => {
416
+ this.ws.on(WebSocketShardEvents.HeartbeatComplete, ({ heartbeatAt, latency }: { heartbeatAt: number; latency: number }, shardId: number) => {
412
417
  this.emit(Events.Debug, `[WS => Shard ${shardId}] Heartbeat acknowledged, latency of ${latency}ms.`);
413
418
  this.lastPingTimestamps.set(shardId, heartbeatAt);
414
419
  this.pings.set(shardId, latency);
@@ -422,7 +427,7 @@ export class Client extends AsyncEventEmitter {
422
427
  * @param {number} shardId The shardId that received this packet
423
428
  * @private
424
429
  */
425
- async _handlePacket(packet, shardId) {
430
+ async _handlePacket(packet: any, shardId: number) {
426
431
  if (this.status !== Status.Ready && !BeforeReadyWhitelist.includes(packet.t)) {
427
432
  this.incomingPacketQueue.push({ packet, shardId });
428
433
  } else {
@@ -433,8 +438,9 @@ export class Client extends AsyncEventEmitter {
433
438
  }).unref();
434
439
  }
435
440
 
436
- if (PacketHandlers[packet.t]) {
437
- PacketHandlers[packet.t](this, packet, shardId);
441
+ const handler = PacketHandlers[packet.t];
442
+ if (handler) {
443
+ handler(this, packet, shardId);
438
444
  }
439
445
 
440
446
  if (packet.t === GatewayDispatchEvents.Ready) {
@@ -446,13 +452,21 @@ export class Client extends AsyncEventEmitter {
446
452
  }
447
453
  }
448
454
 
455
+ get intents() {
456
+ return new IntentsBitField(this.options.intents);
457
+ }
458
+
459
+ async fetchGatewayInformation() {
460
+ return this.rest.get(Routes.gatewayBot());
461
+ }
462
+
449
463
  /**
450
464
  * Broadcasts a packet to every shard of this client handles.
451
465
  *
452
466
  * @param {Object} packet The packet to send
453
467
  * @private
454
468
  */
455
- async _broadcast(packet) {
469
+ async _broadcast(packet: any) {
456
470
  const shardIds = await this.ws.getShardIds();
457
471
  return Promise.all(shardIds.map(shardId => this.ws.send(shardId, packet)));
458
472
  }
@@ -496,13 +510,7 @@ export class Client extends AsyncEventEmitter {
496
510
  return this.pings.size ? this.pings.reduce((a, b) => a + b, 0) / this.pings.size : null;
497
511
  }
498
512
 
499
- /**
500
- * Options used for deleting a webhook.
501
- *
502
- * @typedef {Object} WebhookDeleteOptions
503
- * @property {string} [token] Token of the webhook
504
- * @property {string} [reason] The reason for deleting the webhook
505
- */
513
+
506
514
 
507
515
  /**
508
516
  * Deletes a webhook.
@@ -511,7 +519,7 @@ export class Client extends AsyncEventEmitter {
511
519
  * @param {WebhookDeleteOptions} [options] Options for deleting the webhook
512
520
  * @returns {Promise<void>}
513
521
  */
514
- async deleteWebhook(id, { token, reason } = {}) {
522
+ async deleteWebhook(id: string, { token, reason }: WebhookDeleteOptions = {}) {
515
523
  await this.rest.delete(Routes.webhook(id, token), { auth: !token, reason });
516
524
  }
517
525
 
@@ -551,17 +559,10 @@ export class Client extends AsyncEventEmitter {
551
559
  this.sweepers.destroy();
552
560
  await this.ws.destroy();
553
561
  this.token = null;
554
- this.rest.setToken(null);
562
+ this.rest.setToken(null as any);
555
563
  }
556
564
 
557
- /**
558
- * Options used when fetching an invite from Discord.
559
- *
560
- * @typedef {Object} ClientFetchInviteOptions
561
- * @property {boolean} [withCounts] Whether to include approximate member counts
562
- * @property {Snowflake} [guildScheduledEventId] The id of the guild scheduled event to include with
563
- * the invite
564
- */
565
+
565
566
 
566
567
  /**
567
568
  * Obtains an invite from Discord.
@@ -574,7 +575,7 @@ export class Client extends AsyncEventEmitter {
574
575
  * .then(invite => console.log(`Obtained invite with code: ${invite.code}`))
575
576
  * .catch(console.error);
576
577
  */
577
- async fetchInvite(invite, { withCounts, guildScheduledEventId } = {}) {
578
+ async fetchInvite(invite: any, { withCounts, guildScheduledEventId }: ClientFetchInviteOptions = {}) {
578
579
  const code = resolveInviteCode(invite);
579
580
 
580
581
  const query = makeURLSearchParams({
@@ -596,7 +597,7 @@ export class Client extends AsyncEventEmitter {
596
597
  * .then(template => console.log(`Obtained template with code: ${template.code}`))
597
598
  * .catch(console.error);
598
599
  */
599
- async fetchGuildTemplate(template) {
600
+ async fetchGuildTemplate(template: string) {
600
601
  const code = resolveGuildTemplateCode(template);
601
602
  const data = await this.rest.get(Routes.template(code));
602
603
  return new GuildTemplate(this, data);
@@ -613,8 +614,8 @@ export class Client extends AsyncEventEmitter {
613
614
  * .then(webhook => console.log(`Obtained webhook with name: ${webhook.name}`))
614
615
  * .catch(console.error);
615
616
  */
616
- async fetchWebhook(id, token) {
617
- const data = await this.rest.get(Routes.webhook(id, token), { auth: token === undefined });
617
+ async fetchWebhook(id: string, token?: string) {
618
+ const data = await this.rest.get(Routes.webhook(id, token), { auth: token === undefined }) as any;
618
619
  return new Webhook(this, { token, ...data });
619
620
  }
620
621
 
@@ -628,7 +629,7 @@ export class Client extends AsyncEventEmitter {
628
629
  * .catch(console.error);
629
630
  */
630
631
  async fetchVoiceRegions() {
631
- const apiRegions = await this.rest.get(Routes.voiceRegions());
632
+ const apiRegions = await this.rest.get(Routes.voiceRegions()) as any[];
632
633
  const regions = new Collection();
633
634
  for (const region of apiRegions) regions.set(region.id, new VoiceRegion(region));
634
635
  return regions;
@@ -644,17 +645,12 @@ export class Client extends AsyncEventEmitter {
644
645
  * .then(sticker => console.log(`Obtained sticker with name: ${sticker.name}`))
645
646
  * .catch(console.error);
646
647
  */
647
- async fetchSticker(id) {
648
+ async fetchSticker(id: string) {
648
649
  const data = await this.rest.get(Routes.sticker(id));
649
650
  return new Sticker(this, data);
650
651
  }
651
652
 
652
- /**
653
- * Options for fetching sticker packs.
654
- *
655
- * @typedef {Object} StickerPackFetchOptions
656
- * @property {Snowflake} [packId] The id of the sticker pack to fetch
657
- */
653
+
658
654
 
659
655
  /**
660
656
  * Obtains the list of available sticker packs.
@@ -671,14 +667,14 @@ export class Client extends AsyncEventEmitter {
671
667
  * .then(pack => console.log(`Sticker pack name: ${pack.name}`))
672
668
  * .catch(console.error);
673
669
  */
674
- async fetchStickerPacks({ packId } = {}) {
670
+ async fetchStickerPacks({ packId }: StickerPackFetchOptions = {}) {
675
671
  if (packId) {
676
- const innerData = await this.rest.get(Routes.stickerPack(packId));
672
+ const innerData = await this.rest.get(Routes.stickerPack(packId)) as any;
677
673
  return new StickerPack(this, innerData);
678
674
  }
679
675
 
680
- const data = await this.rest.get(Routes.stickerPacks());
681
- return new Collection(data.sticker_packs.map(stickerPack => [stickerPack.id, new StickerPack(this, stickerPack)]));
676
+ const data = await this.rest.get(Routes.stickerPacks()) as any;
677
+ return new Collection(data.sticker_packs.map((stickerPack: any) => [stickerPack.id, new StickerPack(this, stickerPack)]));
682
678
  }
683
679
 
684
680
  /**
@@ -691,8 +687,8 @@ export class Client extends AsyncEventEmitter {
691
687
  * .catch(console.error);
692
688
  */
693
689
  async fetchDefaultSoundboardSounds() {
694
- const data = await this.rest.get(Routes.soundboardDefaultSounds());
695
- return new Collection(data.map(sound => [sound.sound_id, new SoundboardSound(this, sound)]));
690
+ const data = await this.rest.get(Routes.soundboardDefaultSounds()) as any;
691
+ return new Collection(data.map((sound: any) => [sound.sound_id, new SoundboardSound(this, sound)]));
696
692
  }
697
693
 
698
694
  /**
@@ -701,10 +697,10 @@ export class Client extends AsyncEventEmitter {
701
697
  * @param {GuildResolvable} guild The guild to fetch the preview for
702
698
  * @returns {Promise<GuildPreview>}
703
699
  */
704
- async fetchGuildPreview(guild) {
700
+ async fetchGuildPreview(guild: any) {
705
701
  const id = this.guilds.resolveId(guild);
706
702
  if (!id) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'guild', 'GuildResolvable');
707
- const data = await this.rest.get(Routes.guildPreview(id));
703
+ const data = await this.rest.get(Routes.guildPreview(id)) as any;
708
704
  return new GuildPreview(this, data);
709
705
  }
710
706
 
@@ -714,22 +710,14 @@ export class Client extends AsyncEventEmitter {
714
710
  * @param {GuildResolvable} guild The guild to fetch the widget data for
715
711
  * @returns {Promise<Widget>}
716
712
  */
717
- async fetchGuildWidget(guild) {
713
+ async fetchGuildWidget(guild: any) {
718
714
  const id = this.guilds.resolveId(guild);
719
715
  if (!id) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'guild', 'GuildResolvable');
720
- const data = await this.rest.get(Routes.guildWidgetJSON(id));
716
+ const data = await this.rest.get(Routes.guildWidgetJSON(id)) as any;
721
717
  return new Widget(this, data);
722
718
  }
723
719
 
724
- /**
725
- * Options for {@link Client#generateInvite}.
726
- *
727
- * @typedef {Object} InviteGenerationOptions
728
- * @property {OAuth2Scopes[]} scopes Scopes that should be requested
729
- * @property {PermissionResolvable} [permissions] Permissions to request
730
- * @property {GuildResolvable} [guild] Guild to preselect
731
- * @property {boolean} [disableGuildSelect] Whether to disable the guild selection
732
- */
720
+
733
721
 
734
722
  /**
735
723
  * Generates a link that can be used to invite the bot to a guild.
@@ -752,7 +740,7 @@ export class Client extends AsyncEventEmitter {
752
740
  * });
753
741
  * console.log(`Generated bot invite link: ${link}`);
754
742
  */
755
- generateInvite(options = {}) {
743
+ generateInvite(options: InviteGenerationOptions | any = {}) {
756
744
  if (typeof options !== 'object') throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'options', 'object', true);
757
745
  if (!this.application) throw new DiscordjsError(ErrorCodes.ClientNotReady, 'generate an invite link');
758
746
 
@@ -827,7 +815,7 @@ export class Client extends AsyncEventEmitter {
827
815
  * @returns {*}
828
816
  * @private
829
817
  */
830
- _eval(script) {
818
+ _eval(script: string) {
831
819
  // eslint-disable-next-line no-eval
832
820
  return eval(script);
833
821
  }
@@ -14,39 +14,41 @@ that WebSocket events don't clash with REST methods.
14
14
 
15
15
  */
16
16
 
17
+ import type { Client } from '../Client.js';
18
+
17
19
  export class Action {
18
- public client: any;
19
- constructor(client) {
20
+ public client: Client;
21
+ constructor(client: Client) {
20
22
  this.client = client;
21
23
  }
22
24
 
23
- handle(data) {
24
- return data;
25
+ handle(...data: any[]) {
26
+ return data[0];
25
27
  }
26
28
 
27
- getPayload(data, manager, id, partialType, cache) {
29
+ getPayload(data: any, manager: any, id: any, partialType: any, cache: any) {
28
30
  return this.client.options.partials.includes(partialType) ? manager._add(data, cache) : manager.cache.get(id);
29
31
  }
30
32
 
31
- getChannel(data) {
32
- const payloadData = {};
33
+ getChannel(data: any) {
34
+ const payloadData: Record<string, any> = {};
33
35
  const id = data.channel_id ?? data.id;
34
36
 
35
37
  if (!('recipients' in data)) {
36
38
  // Try to resolve the recipient, but do not add the client user.
37
39
  const recipient = data.author ?? data.user ?? { id: data.user_id };
38
- if (recipient.id !== this.client.user.id) payloadData.recipients = [recipient];
40
+ if (recipient.id !== this.client.user?.id) payloadData.recipients = [recipient];
39
41
  }
40
42
 
41
43
  if (id !== undefined) payloadData.id = id;
42
44
 
43
45
  return (
44
46
  data[this.client.actions.injectedChannel] ??
45
- this.getPayload({ ...data, ...payloadData }, this.client.channels, id, Partials.Channel)
47
+ this.getPayload({ ...data, ...payloadData }, this.client.channels, id, Partials.Channel, undefined)
46
48
  );
47
49
  }
48
50
 
49
- getMessage(data, channel, cache) {
51
+ getMessage(data: any, channel: any, cache: any) {
50
52
  const id = data.message_id ?? data.id;
51
53
  return (
52
54
  data[this.client.actions.injectedMessage] ??
@@ -64,7 +66,7 @@ export class Action {
64
66
  );
65
67
  }
66
68
 
67
- getPoll(data, message, channel) {
69
+ getPoll(data: any, message: any, channel: any) {
68
70
  const includePollPartial = this.client.options.partials.includes(Partials.Poll);
69
71
  const includePollAnswerPartial = this.client.options.partials.includes(Partials.PollAnswer);
70
72
  if (message.partial && (!includePollPartial || !includePollAnswerPartial)) return null;
@@ -81,30 +83,31 @@ export class Action {
81
83
  return message.poll;
82
84
  }
83
85
 
84
- getReaction(data, message, user) {
86
+ getReaction(data: any, message: any, user: any) {
85
87
  const id = data.emoji.id ?? decodeURIComponent(data.emoji.name);
86
88
  return this.getPayload(
87
89
  {
88
90
  emoji: data.emoji,
89
91
  count: message.partial ? null : 0,
90
- me: user?.id === this.client.user.id,
92
+ me: user?.id === this.client.user?.id,
91
93
  },
92
94
  message.reactions,
93
95
  id,
94
96
  Partials.Reaction,
97
+ undefined,
95
98
  );
96
99
  }
97
100
 
98
- getMember(data, guild) {
99
- return this.getPayload(data, guild.members, data.user.id, Partials.GuildMember);
101
+ getMember(data: any, guild: any) {
102
+ return this.getPayload(data, guild.members, data.user.id, Partials.GuildMember, undefined);
100
103
  }
101
104
 
102
- getUser(data) {
105
+ getUser(data: any) {
103
106
  const id = data.user_id;
104
- return data[this.client.actions.injectedUser] ?? this.getPayload({ id }, this.client.users, id, Partials.User);
107
+ return data[this.client.actions.injectedUser] ?? this.getPayload({ id }, this.client.users, id, Partials.User, undefined);
105
108
  }
106
109
 
107
- getUserFromMember(data) {
110
+ getUserFromMember(data: any) {
108
111
  if (data.guild_id && data.member?.user) {
109
112
  const guild = this.client.guilds.cache.get(data.guild_id);
110
113
  if (guild) {
@@ -117,25 +120,26 @@ export class Action {
117
120
  return this.getUser(data);
118
121
  }
119
122
 
120
- getScheduledEvent(data, guild) {
123
+ getScheduledEvent(data: any, guild: any) {
121
124
  const id = data.guild_scheduled_event_id ?? data.id;
122
125
  return this.getPayload(
123
126
  { id, guild_id: data.guild_id ?? guild.id },
124
127
  guild.scheduledEvents,
125
128
  id,
126
129
  Partials.GuildScheduledEvent,
130
+ undefined,
127
131
  );
128
132
  }
129
133
 
130
- getThreadMember(id, manager) {
134
+ getThreadMember(id: any, manager: any) {
131
135
  return this.getPayload({ user_id: id }, manager, id, Partials.ThreadMember, false);
132
136
  }
133
137
 
134
- getSoundboardSound(data, guild) {
135
- return this.getPayload(data, guild.soundboardSounds, data.sound_id, Partials.SoundboardSound);
138
+ getSoundboardSound(data: any, guild: any) {
139
+ return this.getPayload(data, guild.soundboardSounds, data.sound_id, Partials.SoundboardSound, undefined);
136
140
  }
137
141
 
138
- spreadInjectedData(data) {
142
+ spreadInjectedData(data: any) {
139
143
  return Object.fromEntries(Object.getOwnPropertySymbols(data).map(symbol => [symbol, data[symbol]]));
140
144
  }
141
145
  }
@@ -2,10 +2,10 @@ import { Events } from '../../util/Events.js';
2
2
  import { Action } from './Action.js';
3
3
 
4
4
  export class ChannelCreateAction extends Action {
5
- handle(data) {
5
+ override handle(data: any) {
6
6
  const client = this.client;
7
7
  const existing = client.channels.cache.has(data.id);
8
- const channel = client.channels._add(data);
8
+ const channel = client.channels._add(data, client.guilds.cache.get(data.guild_id) ?? null);
9
9
  if (!existing && channel) {
10
10
  /**
11
11
  * Emitted whenever a guild channel is created.
@@ -2,7 +2,7 @@ import { Events } from '../../util/Events.js';
2
2
  import { Action } from './Action.js';
3
3
 
4
4
  export class ChannelDeleteAction extends Action {
5
- handle(data) {
5
+ override handle(data: any) {
6
6
  const client = this.client;
7
7
  const channel = client.channels.cache.get(data.id);
8
8
 
@@ -2,7 +2,7 @@ import { createChannel } from '../../util/Channels.js';
2
2
  import { Action } from './Action.js';
3
3
 
4
4
  export class ChannelUpdateAction extends Action {
5
- handle(data) {
5
+ override handle(data: any) {
6
6
  const client = this.client;
7
7
  let channel = client.channels.cache.get(data.id);
8
8
 
@@ -30,7 +30,7 @@ export class ChannelUpdateAction extends Action {
30
30
  updated: channel,
31
31
  };
32
32
  } else {
33
- client.channels._add(data);
33
+ client.channels._add(data, client.guilds.cache.get(data.guild_id) ?? null);
34
34
  }
35
35
 
36
36
  return {};
@@ -1,7 +1,7 @@
1
1
  import { Action } from './Action.js';
2
2
 
3
3
  export class GuildChannelsPositionUpdateAction extends Action {
4
- handle(data) {
4
+ override handle(data: any) {
5
5
  const client = this.client;
6
6
 
7
7
  const guild = client.guilds.cache.get(data.guild_id);
@@ -2,7 +2,7 @@ import { Events } from '../../util/Events.js';
2
2
  import { Action } from './Action.js';
3
3
 
4
4
  export class GuildEmojiCreateAction extends Action {
5
- handle(guild, createdEmoji) {
5
+ override handle(guild: any, createdEmoji: any) {
6
6
  const already = guild.emojis.cache.has(createdEmoji.id);
7
7
  const emoji = guild.emojis._add(createdEmoji);
8
8
  /**