discord.js 15.0.0-dev.1737227217-9ad40b751 → 15.0.0-dev.1737245587-aa90f00d1

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "discord.js",
4
- "version": "15.0.0-dev.1737227217-9ad40b751",
4
+ "version": "15.0.0-dev.1737245587-aa90f00d1",
5
5
  "description": "A powerful library for interacting with the Discord API",
6
6
  "main": "./src/index.js",
7
7
  "types": "./typings/index.d.ts",
@@ -54,14 +54,13 @@
54
54
  "dependencies": {
55
55
  "@discordjs/builders": "^1.9.0",
56
56
  "@sapphire/snowflake": "3.5.5",
57
- "@vladfrangu/async_event_emitter": "^2.4.6",
58
57
  "discord-api-types": "^0.37.114",
59
58
  "fast-deep-equal": "3.1.3",
60
59
  "lodash.snakecase": "4.1.1",
61
60
  "tslib": "^2.8.1",
62
61
  "undici": "6.21.0",
63
- "@discordjs/collection": "^2.1.1",
64
62
  "@discordjs/formatters": "^0.5.0",
63
+ "@discordjs/collection": "^2.1.1",
65
64
  "@discordjs/util": "^1.1.1",
66
65
  "@discordjs/ws": "^2.0.0",
67
66
  "@discordjs/rest": "^2.4.0"
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ const EventEmitter = require('node:events');
3
4
  const { REST } = require('@discordjs/rest');
4
- const { AsyncEventEmitter } = require('@vladfrangu/async_event_emitter');
5
5
  const { Routes } = require('discord-api-types/v10');
6
6
  const { DiscordjsTypeError, ErrorCodes } = require('../errors');
7
7
  const { Options } = require('../util/Options');
@@ -9,11 +9,11 @@ const { flatten } = require('../util/Util');
9
9
 
10
10
  /**
11
11
  * The base class for all clients.
12
- * @extends {AsyncEventEmitter}
12
+ * @extends {EventEmitter}
13
13
  */
14
- class BaseClient extends AsyncEventEmitter {
14
+ class BaseClient extends EventEmitter {
15
15
  constructor(options = {}) {
16
- super();
16
+ super({ captureRejections: true });
17
17
 
18
18
  if (typeof options !== 'object' || options === null) {
19
19
  throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'options', 'object', true);
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
+ const EventEmitter = require('node:events');
3
4
  const path = require('node:path');
4
5
  const process = require('node:process');
5
6
  const { setTimeout, clearTimeout } = require('node:timers');
6
7
  const { setTimeout: sleep } = require('node:timers/promises');
7
8
  const { SHARE_ENV } = require('node:worker_threads');
8
- const { AsyncEventEmitter } = require('@vladfrangu/async_event_emitter');
9
9
  const { DiscordjsError, ErrorCodes } = require('../errors');
10
10
  const { ShardEvents } = require('../util/ShardEvents');
11
11
  const { makeError, makePlainError } = require('../util/Util');
@@ -17,9 +17,9 @@ let Worker = null;
17
17
  * A self-contained shard created by the {@link ShardingManager}. Each one has a {@link ChildProcess} that contains
18
18
  * an instance of the bot and its {@link Client}. When its child process/worker exits for any reason, the shard will
19
19
  * spawn a new one to replace it as necessary.
20
- * @extends {AsyncEventEmitter}
20
+ * @extends {EventEmitter}
21
21
  */
22
- class Shard extends AsyncEventEmitter {
22
+ class Shard extends EventEmitter {
23
23
  constructor(manager, id) {
24
24
  super();
25
25
 
@@ -445,7 +445,7 @@ class Shard extends AsyncEventEmitter {
445
445
 
446
446
  /**
447
447
  * Increments max listeners by one for a given emitter, if they are not zero.
448
- * @param {Worker|ChildProcess} emitter The emitter that emits the events.
448
+ * @param {EventEmitter|process} emitter The emitter that emits the events.
449
449
  * @private
450
450
  */
451
451
  incrementMaxListeners(emitter) {
@@ -457,7 +457,7 @@ class Shard extends AsyncEventEmitter {
457
457
 
458
458
  /**
459
459
  * Decrements max listeners by one for a given emitter, if they are not zero.
460
- * @param {Worker|ChildProcess} emitter The emitter that emits the events.
460
+ * @param {EventEmitter|process} emitter The emitter that emits the events.
461
461
  * @private
462
462
  */
463
463
  decrementMaxListeners(emitter) {
@@ -242,7 +242,7 @@ class ShardClientUtil {
242
242
 
243
243
  /**
244
244
  * Increments max listeners by one for a given emitter, if they are not zero.
245
- * @param {Worker|ChildProcess} emitter The emitter that emits the events.
245
+ * @param {EventEmitter|process} emitter The emitter that emits the events.
246
246
  * @private
247
247
  */
248
248
  incrementMaxListeners(emitter) {
@@ -254,7 +254,7 @@ class ShardClientUtil {
254
254
 
255
255
  /**
256
256
  * Decrements max listeners by one for a given emitter, if they are not zero.
257
- * @param {Worker|ChildProcess} emitter The emitter that emits the events.
257
+ * @param {EventEmitter|process} emitter The emitter that emits the events.
258
258
  * @private
259
259
  */
260
260
  decrementMaxListeners(emitter) {
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
+ const EventEmitter = require('node:events');
3
4
  const fs = require('node:fs');
4
5
  const path = require('node:path');
5
6
  const process = require('node:process');
6
7
  const { setTimeout: sleep } = require('node:timers/promises');
7
8
  const { Collection } = require('@discordjs/collection');
8
- const { AsyncEventEmitter } = require('@vladfrangu/async_event_emitter');
9
9
  const { Shard } = require('./Shard');
10
10
  const { DiscordjsError, DiscordjsTypeError, DiscordjsRangeError, ErrorCodes } = require('../errors');
11
11
  const { fetchRecommendedShardCount } = require('../util/Util');
@@ -17,9 +17,9 @@ const { fetchRecommendedShardCount } = require('../util/Util');
17
17
  * process, and there are several useful methods that utilize it in order to simplify tasks that are normally difficult
18
18
  * with sharding. It can spawn a specific number of shards or the amount that Discord suggests for the bot, and takes a
19
19
  * path to your main bot script to launch for each one.
20
- * @extends {AsyncEventEmitter}
20
+ * @extends {EventEmitter}
21
21
  */
22
- class ShardingManager extends AsyncEventEmitter {
22
+ class ShardingManager extends EventEmitter {
23
23
  /**
24
24
  * The mode to spawn shards with for a {@link ShardingManager}. Can be either one of:
25
25
  * * 'process' to use child processes
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
+ const EventEmitter = require('node:events');
3
4
  const { setTimeout, clearTimeout } = require('node:timers');
4
5
  const { Collection } = require('@discordjs/collection');
5
- const { AsyncEventEmitter } = require('@vladfrangu/async_event_emitter');
6
6
  const { DiscordjsTypeError, ErrorCodes } = require('../../errors');
7
7
  const { flatten } = require('../../util/Util');
8
8
 
@@ -25,10 +25,10 @@ const { flatten } = require('../../util/Util');
25
25
 
26
26
  /**
27
27
  * Abstract class for defining a new Collector.
28
- * @extends {AsyncEventEmitter}
28
+ * @extends {EventEmitter}
29
29
  * @abstract
30
30
  */
31
- class Collector extends AsyncEventEmitter {
31
+ class Collector extends EventEmitter {
32
32
  constructor(client, options = {}) {
33
33
  super();
34
34
 
@@ -20,7 +20,6 @@ import { Awaitable, JSONEncodable } from '@discordjs/util';
20
20
  import { Collection, ReadonlyCollection } from '@discordjs/collection';
21
21
  import { BaseImageURLOptions, ImageURLOptions, RawFile, REST, RESTOptions } from '@discordjs/rest';
22
22
  import { WebSocketManager, WebSocketManagerOptions } from '@discordjs/ws';
23
- import { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';
24
23
  import {
25
24
  APIActionRowComponent,
26
25
  APIApplicationCommandInteractionData,
@@ -178,6 +177,7 @@ import {
178
177
  GatewayVoiceChannelEffectSendDispatchData,
179
178
  } from 'discord-api-types/v10';
180
179
  import { ChildProcess } from 'node:child_process';
180
+ import { EventEmitter } from 'node:events';
181
181
  import { Stream } from 'node:stream';
182
182
  import { MessagePort, Worker } from 'node:worker_threads';
183
183
  import {
@@ -515,7 +515,7 @@ export abstract class Base {
515
515
  public valueOf(): string;
516
516
  }
517
517
 
518
- export class BaseClient<Events extends {}> extends AsyncEventEmitter<Events> implements AsyncDisposable {
518
+ export class BaseClient extends EventEmitter implements AsyncDisposable {
519
519
  public constructor(options?: ClientOptions | WebhookClientOptions);
520
520
  private decrementMaxListeners(): void;
521
521
  private incrementMaxListeners(): void;
@@ -959,7 +959,7 @@ export type If<Value extends boolean, TrueResult, FalseResult = null> = Value ex
959
959
  ? FalseResult
960
960
  : TrueResult | FalseResult;
961
961
 
962
- export class Client<Ready extends boolean = boolean> extends BaseClient<ClientEvents> {
962
+ export class Client<Ready extends boolean = boolean> extends BaseClient {
963
963
  public constructor(options: ClientOptions);
964
964
  private actions: unknown;
965
965
  private expectedGuilds: Set<Snowflake>;
@@ -977,6 +977,18 @@ export class Client<Ready extends boolean = boolean> extends BaseClient<ClientEv
977
977
  // This a technique used to brand the ready state. Or else we'll get `never` errors on typeguard checks.
978
978
  private readonly _ready: Ready;
979
979
 
980
+ // Override inherited static EventEmitter methods, with added type checks for Client events.
981
+ public static once<Emitter extends EventEmitter, Event extends keyof ClientEvents>(
982
+ eventEmitter: Emitter,
983
+ eventName: Emitter extends Client ? Event : string | symbol,
984
+ options?: { signal?: AbortSignal | undefined },
985
+ ): Promise<Emitter extends Client ? ClientEvents[Event] : any[]>;
986
+ public static on<Emitter extends EventEmitter, Event extends keyof ClientEvents>(
987
+ eventEmitter: Emitter,
988
+ eventName: Emitter extends Client ? Event : string | symbol,
989
+ options?: { signal?: AbortSignal | undefined },
990
+ ): AsyncIterableIterator<Emitter extends Client ? ClientEvents[Event] : any[]>;
991
+
980
992
  public application: If<Ready, ClientApplication>;
981
993
  public channels: ChannelManager;
982
994
  public get emojis(): BaseGuildEmojiManager;
@@ -1011,6 +1023,30 @@ export class Client<Ready extends boolean = boolean> extends BaseClient<ClientEv
1011
1023
  public login(token?: string): Promise<string>;
1012
1024
  public isReady(): this is Client<true>;
1013
1025
  public toJSON(): unknown;
1026
+
1027
+ public on<Event extends keyof ClientEvents>(event: Event, listener: (...args: ClientEvents[Event]) => void): this;
1028
+ public on<Event extends string | symbol>(
1029
+ event: Exclude<Event, keyof ClientEvents>,
1030
+ listener: (...args: any[]) => void,
1031
+ ): this;
1032
+
1033
+ public once<Event extends keyof ClientEvents>(event: Event, listener: (...args: ClientEvents[Event]) => void): this;
1034
+ public once<Event extends string | symbol>(
1035
+ event: Exclude<Event, keyof ClientEvents>,
1036
+ listener: (...args: any[]) => void,
1037
+ ): this;
1038
+
1039
+ public emit<Event extends keyof ClientEvents>(event: Event, ...args: ClientEvents[Event]): boolean;
1040
+ public emit<Event extends string | symbol>(event: Exclude<Event, keyof ClientEvents>, ...args: unknown[]): boolean;
1041
+
1042
+ public off<Event extends keyof ClientEvents>(event: Event, listener: (...args: ClientEvents[Event]) => void): this;
1043
+ public off<Event extends string | symbol>(
1044
+ event: Exclude<Event, keyof ClientEvents>,
1045
+ listener: (...args: any[]) => void,
1046
+ ): this;
1047
+
1048
+ public removeAllListeners<Event extends keyof ClientEvents>(event?: Event): this;
1049
+ public removeAllListeners<Event extends string | symbol>(event?: Exclude<Event, keyof ClientEvents>): this;
1014
1050
  }
1015
1051
 
1016
1052
  export interface StickerPackFetchOptions {
@@ -1098,9 +1134,7 @@ export interface CollectorEventTypes<Key, Value, Extras extends unknown[] = []>
1098
1134
  end: [collected: ReadonlyCollection<Key, Value>, reason: string];
1099
1135
  }
1100
1136
 
1101
- export abstract class Collector<Key, Value, Extras extends unknown[] = []> extends AsyncEventEmitter<
1102
- CollectorEventTypes<Key, Value, Extras>
1103
- > {
1137
+ export abstract class Collector<Key, Value, Extras extends unknown[] = []> extends EventEmitter {
1104
1138
  protected constructor(client: Client<true>, options?: CollectorOptions<[Value, ...Extras]>);
1105
1139
  private _timeout: NodeJS.Timeout | null;
1106
1140
  private _idletimeout: NodeJS.Timeout | null;
@@ -1126,6 +1160,16 @@ export abstract class Collector<Key, Value, Extras extends unknown[] = []> exten
1126
1160
  protected listener: (...args: any[]) => void;
1127
1161
  public abstract collect(...args: unknown[]): Awaitable<Key | null>;
1128
1162
  public abstract dispose(...args: unknown[]): Key | null;
1163
+
1164
+ public on<EventKey extends keyof CollectorEventTypes<Key, Value, Extras>>(
1165
+ event: EventKey,
1166
+ listener: (...args: CollectorEventTypes<Key, Value, Extras>[EventKey]) => void,
1167
+ ): this;
1168
+
1169
+ public once<EventKey extends keyof CollectorEventTypes<Key, Value, Extras>>(
1170
+ event: EventKey,
1171
+ listener: (...args: CollectorEventTypes<Key, Value, Extras>[EventKey]) => void,
1172
+ ): this;
1129
1173
  }
1130
1174
 
1131
1175
  export class ChatInputCommandInteraction<Cached extends CacheType = CacheType> extends CommandInteraction<Cached> {
@@ -1987,6 +2031,19 @@ export class InteractionCollector<Interaction extends CollectedInteraction> exte
1987
2031
  public collect(interaction: Interaction): Snowflake;
1988
2032
  public empty(): void;
1989
2033
  public dispose(interaction: Interaction): Snowflake;
2034
+ public on(event: 'collect' | 'dispose' | 'ignore', listener: (interaction: Interaction) => void): this;
2035
+ public on(
2036
+ event: 'end',
2037
+ listener: (collected: ReadonlyCollection<Snowflake, Interaction>, reason: string) => void,
2038
+ ): this;
2039
+ public on(event: string, listener: (...args: any[]) => void): this;
2040
+
2041
+ public once(event: 'collect' | 'dispose' | 'ignore', listener: (interaction: Interaction) => void): this;
2042
+ public once(
2043
+ event: 'end',
2044
+ listener: (collected: ReadonlyCollection<Snowflake, Interaction>, reason: string) => void,
2045
+ ): this;
2046
+ public once(event: string, listener: (...args: any[]) => void): this;
1990
2047
  }
1991
2048
 
1992
2049
  // tslint:disable-next-line no-empty-interface
@@ -2726,6 +2783,26 @@ export class ReactionCollector extends Collector<Snowflake | string, MessageReac
2726
2783
  public collect(reaction: MessageReaction, user: User): Snowflake | string | null;
2727
2784
  public dispose(reaction: MessageReaction, user: User): Snowflake | string | null;
2728
2785
  public empty(): void;
2786
+
2787
+ public on(
2788
+ event: 'collect' | 'dispose' | 'remove' | 'ignore',
2789
+ listener: (reaction: MessageReaction, user: User) => void,
2790
+ ): this;
2791
+ public on(
2792
+ event: 'end',
2793
+ listener: (collected: ReadonlyCollection<Snowflake, MessageReaction>, reason: string) => void,
2794
+ ): this;
2795
+ public on(event: string, listener: (...args: any[]) => void): this;
2796
+
2797
+ public once(
2798
+ event: 'collect' | 'dispose' | 'remove' | 'ignore',
2799
+ listener: (reaction: MessageReaction, user: User) => void,
2800
+ ): this;
2801
+ public once(
2802
+ event: 'end',
2803
+ listener: (collected: ReadonlyCollection<Snowflake, MessageReaction>, reason: string) => void,
2804
+ ): this;
2805
+ public once(event: string, listener: (...args: any[]) => void): this;
2729
2806
  }
2730
2807
 
2731
2808
  export class ReactionEmoji extends Emoji {
@@ -2920,15 +2997,15 @@ export interface ShardEventTypes {
2920
2997
  spawn: [process: ChildProcess | Worker];
2921
2998
  }
2922
2999
 
2923
- export class Shard extends AsyncEventEmitter<ShardEventTypes> {
3000
+ export class Shard extends EventEmitter {
2924
3001
  private constructor(manager: ShardingManager, id: number);
2925
3002
  private _evals: Map<string, Promise<unknown>>;
2926
3003
  private _exitListener: (...args: any[]) => void;
2927
3004
  private _fetches: Map<string, Promise<unknown>>;
2928
3005
  private _handleExit(respawn?: boolean, timeout?: number): void;
2929
3006
  private _handleMessage(message: unknown): void;
2930
- private incrementMaxListeners(emitter: Worker | ChildProcess): void;
2931
- private decrementMaxListeners(emitter: Worker | ChildProcess): void;
3007
+ private incrementMaxListeners(emitter: EventEmitter | ChildProcess): void;
3008
+ private decrementMaxListeners(emitter: EventEmitter | ChildProcess): void;
2932
3009
 
2933
3010
  public args: string[];
2934
3011
  public execArgv: string[];
@@ -2950,14 +3027,24 @@ export class Shard extends AsyncEventEmitter<ShardEventTypes> {
2950
3027
  public respawn(options?: { delay?: number; timeout?: number }): Promise<ChildProcess>;
2951
3028
  public send(message: unknown): Promise<Shard>;
2952
3029
  public spawn(timeout?: number): Promise<ChildProcess>;
3030
+
3031
+ public on<Event extends keyof ShardEventTypes>(
3032
+ event: Event,
3033
+ listener: (...args: ShardEventTypes[Event]) => void,
3034
+ ): this;
3035
+
3036
+ public once<Event extends keyof ShardEventTypes>(
3037
+ event: Event,
3038
+ listener: (...args: ShardEventTypes[Event]) => void,
3039
+ ): this;
2953
3040
  }
2954
3041
 
2955
3042
  export class ShardClientUtil {
2956
3043
  private constructor(client: Client<true>, mode: ShardingManagerMode);
2957
3044
  private _handleMessage(message: unknown): void;
2958
3045
  private _respond(type: string, message: unknown): void;
2959
- private incrementMaxListeners(emitter: Worker | ChildProcess): void;
2960
- private decrementMaxListeners(emitter: Worker | ChildProcess): void;
3046
+ private incrementMaxListeners(emitter: EventEmitter | ChildProcess): void;
3047
+ private decrementMaxListeners(emitter: EventEmitter | ChildProcess): void;
2961
3048
 
2962
3049
  public client: Client;
2963
3050
  public get count(): number;
@@ -2986,11 +3073,7 @@ export class ShardClientUtil {
2986
3073
  public static shardIdForGuildId(guildId: Snowflake, shardCount: number): number;
2987
3074
  }
2988
3075
 
2989
- export interface ShardingManagerEvents {
2990
- shardCreate: [shard: Shard];
2991
- }
2992
-
2993
- export class ShardingManager extends AsyncEventEmitter<ShardingManagerEvents> {
3076
+ export class ShardingManager extends EventEmitter {
2994
3077
  public constructor(file: string, options?: ShardingManagerOptions);
2995
3078
  private _performOnShards(method: string, args: readonly unknown[]): Promise<unknown[]>;
2996
3079
  private _performOnShards(method: string, args: readonly unknown[], shard: number): Promise<unknown>;
@@ -3022,6 +3105,10 @@ export class ShardingManager extends AsyncEventEmitter<ShardingManagerEvents> {
3022
3105
  public fetchClientValues(prop: string, shard: number): Promise<unknown>;
3023
3106
  public respawnAll(options?: MultipleShardRespawnOptions): Promise<Collection<number, Shard>>;
3024
3107
  public spawn(options?: MultipleShardSpawnOptions): Promise<Collection<number, Shard>>;
3108
+
3109
+ public on(event: 'shardCreate', listener: (shard: Shard) => void): this;
3110
+
3111
+ public once(event: 'shardCreate', listener: (shard: Shard) => void): this;
3025
3112
  }
3026
3113
 
3027
3114
  export interface FetchRecommendedShardCountOptions {
@@ -3605,8 +3692,8 @@ export class Webhook<Type extends WebhookType = WebhookType> {
3605
3692
  }
3606
3693
 
3607
3694
  // tslint:disable-next-line no-empty-interface
3608
- export interface WebhookClient extends WebhookFields, BaseClient<{}> {}
3609
- export class WebhookClient extends BaseClient<{}> {
3695
+ export interface WebhookClient extends WebhookFields, BaseClient {}
3696
+ export class WebhookClient extends BaseClient {
3610
3697
  public constructor(data: WebhookClientData, options?: WebhookClientOptions);
3611
3698
  public readonly client: this;
3612
3699
  public options: WebhookClientOptions;
@@ -20,7 +20,6 @@ import { Awaitable, JSONEncodable } from '@discordjs/util';
20
20
  import { Collection, ReadonlyCollection } from '@discordjs/collection';
21
21
  import { BaseImageURLOptions, ImageURLOptions, RawFile, REST, RESTOptions } from '@discordjs/rest';
22
22
  import { WebSocketManager, WebSocketManagerOptions } from '@discordjs/ws';
23
- import { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';
24
23
  import {
25
24
  APIActionRowComponent,
26
25
  APIApplicationCommandInteractionData,
@@ -178,6 +177,7 @@ import {
178
177
  GatewayVoiceChannelEffectSendDispatchData,
179
178
  } from 'discord-api-types/v10';
180
179
  import { ChildProcess } from 'node:child_process';
180
+ import { EventEmitter } from 'node:events';
181
181
  import { Stream } from 'node:stream';
182
182
  import { MessagePort, Worker } from 'node:worker_threads';
183
183
  import {
@@ -515,7 +515,7 @@ export abstract class Base {
515
515
  public valueOf(): string;
516
516
  }
517
517
 
518
- export class BaseClient<Events extends {}> extends AsyncEventEmitter<Events> implements AsyncDisposable {
518
+ export class BaseClient extends EventEmitter implements AsyncDisposable {
519
519
  public constructor(options?: ClientOptions | WebhookClientOptions);
520
520
  private decrementMaxListeners(): void;
521
521
  private incrementMaxListeners(): void;
@@ -959,7 +959,7 @@ export type If<Value extends boolean, TrueResult, FalseResult = null> = Value ex
959
959
  ? FalseResult
960
960
  : TrueResult | FalseResult;
961
961
 
962
- export class Client<Ready extends boolean = boolean> extends BaseClient<ClientEvents> {
962
+ export class Client<Ready extends boolean = boolean> extends BaseClient {
963
963
  public constructor(options: ClientOptions);
964
964
  private actions: unknown;
965
965
  private expectedGuilds: Set<Snowflake>;
@@ -977,6 +977,18 @@ export class Client<Ready extends boolean = boolean> extends BaseClient<ClientEv
977
977
  // This a technique used to brand the ready state. Or else we'll get `never` errors on typeguard checks.
978
978
  private readonly _ready: Ready;
979
979
 
980
+ // Override inherited static EventEmitter methods, with added type checks for Client events.
981
+ public static once<Emitter extends EventEmitter, Event extends keyof ClientEvents>(
982
+ eventEmitter: Emitter,
983
+ eventName: Emitter extends Client ? Event : string | symbol,
984
+ options?: { signal?: AbortSignal | undefined },
985
+ ): Promise<Emitter extends Client ? ClientEvents[Event] : any[]>;
986
+ public static on<Emitter extends EventEmitter, Event extends keyof ClientEvents>(
987
+ eventEmitter: Emitter,
988
+ eventName: Emitter extends Client ? Event : string | symbol,
989
+ options?: { signal?: AbortSignal | undefined },
990
+ ): AsyncIterableIterator<Emitter extends Client ? ClientEvents[Event] : any[]>;
991
+
980
992
  public application: If<Ready, ClientApplication>;
981
993
  public channels: ChannelManager;
982
994
  public get emojis(): BaseGuildEmojiManager;
@@ -1011,6 +1023,30 @@ export class Client<Ready extends boolean = boolean> extends BaseClient<ClientEv
1011
1023
  public login(token?: string): Promise<string>;
1012
1024
  public isReady(): this is Client<true>;
1013
1025
  public toJSON(): unknown;
1026
+
1027
+ public on<Event extends keyof ClientEvents>(event: Event, listener: (...args: ClientEvents[Event]) => void): this;
1028
+ public on<Event extends string | symbol>(
1029
+ event: Exclude<Event, keyof ClientEvents>,
1030
+ listener: (...args: any[]) => void,
1031
+ ): this;
1032
+
1033
+ public once<Event extends keyof ClientEvents>(event: Event, listener: (...args: ClientEvents[Event]) => void): this;
1034
+ public once<Event extends string | symbol>(
1035
+ event: Exclude<Event, keyof ClientEvents>,
1036
+ listener: (...args: any[]) => void,
1037
+ ): this;
1038
+
1039
+ public emit<Event extends keyof ClientEvents>(event: Event, ...args: ClientEvents[Event]): boolean;
1040
+ public emit<Event extends string | symbol>(event: Exclude<Event, keyof ClientEvents>, ...args: unknown[]): boolean;
1041
+
1042
+ public off<Event extends keyof ClientEvents>(event: Event, listener: (...args: ClientEvents[Event]) => void): this;
1043
+ public off<Event extends string | symbol>(
1044
+ event: Exclude<Event, keyof ClientEvents>,
1045
+ listener: (...args: any[]) => void,
1046
+ ): this;
1047
+
1048
+ public removeAllListeners<Event extends keyof ClientEvents>(event?: Event): this;
1049
+ public removeAllListeners<Event extends string | symbol>(event?: Exclude<Event, keyof ClientEvents>): this;
1014
1050
  }
1015
1051
 
1016
1052
  export interface StickerPackFetchOptions {
@@ -1098,9 +1134,7 @@ export interface CollectorEventTypes<Key, Value, Extras extends unknown[] = []>
1098
1134
  end: [collected: ReadonlyCollection<Key, Value>, reason: string];
1099
1135
  }
1100
1136
 
1101
- export abstract class Collector<Key, Value, Extras extends unknown[] = []> extends AsyncEventEmitter<
1102
- CollectorEventTypes<Key, Value, Extras>
1103
- > {
1137
+ export abstract class Collector<Key, Value, Extras extends unknown[] = []> extends EventEmitter {
1104
1138
  protected constructor(client: Client<true>, options?: CollectorOptions<[Value, ...Extras]>);
1105
1139
  private _timeout: NodeJS.Timeout | null;
1106
1140
  private _idletimeout: NodeJS.Timeout | null;
@@ -1126,6 +1160,16 @@ export abstract class Collector<Key, Value, Extras extends unknown[] = []> exten
1126
1160
  protected listener: (...args: any[]) => void;
1127
1161
  public abstract collect(...args: unknown[]): Awaitable<Key | null>;
1128
1162
  public abstract dispose(...args: unknown[]): Key | null;
1163
+
1164
+ public on<EventKey extends keyof CollectorEventTypes<Key, Value, Extras>>(
1165
+ event: EventKey,
1166
+ listener: (...args: CollectorEventTypes<Key, Value, Extras>[EventKey]) => void,
1167
+ ): this;
1168
+
1169
+ public once<EventKey extends keyof CollectorEventTypes<Key, Value, Extras>>(
1170
+ event: EventKey,
1171
+ listener: (...args: CollectorEventTypes<Key, Value, Extras>[EventKey]) => void,
1172
+ ): this;
1129
1173
  }
1130
1174
 
1131
1175
  export class ChatInputCommandInteraction<Cached extends CacheType = CacheType> extends CommandInteraction<Cached> {
@@ -1987,6 +2031,19 @@ export class InteractionCollector<Interaction extends CollectedInteraction> exte
1987
2031
  public collect(interaction: Interaction): Snowflake;
1988
2032
  public empty(): void;
1989
2033
  public dispose(interaction: Interaction): Snowflake;
2034
+ public on(event: 'collect' | 'dispose' | 'ignore', listener: (interaction: Interaction) => void): this;
2035
+ public on(
2036
+ event: 'end',
2037
+ listener: (collected: ReadonlyCollection<Snowflake, Interaction>, reason: string) => void,
2038
+ ): this;
2039
+ public on(event: string, listener: (...args: any[]) => void): this;
2040
+
2041
+ public once(event: 'collect' | 'dispose' | 'ignore', listener: (interaction: Interaction) => void): this;
2042
+ public once(
2043
+ event: 'end',
2044
+ listener: (collected: ReadonlyCollection<Snowflake, Interaction>, reason: string) => void,
2045
+ ): this;
2046
+ public once(event: string, listener: (...args: any[]) => void): this;
1990
2047
  }
1991
2048
 
1992
2049
  // tslint:disable-next-line no-empty-interface
@@ -2726,6 +2783,26 @@ export class ReactionCollector extends Collector<Snowflake | string, MessageReac
2726
2783
  public collect(reaction: MessageReaction, user: User): Snowflake | string | null;
2727
2784
  public dispose(reaction: MessageReaction, user: User): Snowflake | string | null;
2728
2785
  public empty(): void;
2786
+
2787
+ public on(
2788
+ event: 'collect' | 'dispose' | 'remove' | 'ignore',
2789
+ listener: (reaction: MessageReaction, user: User) => void,
2790
+ ): this;
2791
+ public on(
2792
+ event: 'end',
2793
+ listener: (collected: ReadonlyCollection<Snowflake, MessageReaction>, reason: string) => void,
2794
+ ): this;
2795
+ public on(event: string, listener: (...args: any[]) => void): this;
2796
+
2797
+ public once(
2798
+ event: 'collect' | 'dispose' | 'remove' | 'ignore',
2799
+ listener: (reaction: MessageReaction, user: User) => void,
2800
+ ): this;
2801
+ public once(
2802
+ event: 'end',
2803
+ listener: (collected: ReadonlyCollection<Snowflake, MessageReaction>, reason: string) => void,
2804
+ ): this;
2805
+ public once(event: string, listener: (...args: any[]) => void): this;
2729
2806
  }
2730
2807
 
2731
2808
  export class ReactionEmoji extends Emoji {
@@ -2920,15 +2997,15 @@ export interface ShardEventTypes {
2920
2997
  spawn: [process: ChildProcess | Worker];
2921
2998
  }
2922
2999
 
2923
- export class Shard extends AsyncEventEmitter<ShardEventTypes> {
3000
+ export class Shard extends EventEmitter {
2924
3001
  private constructor(manager: ShardingManager, id: number);
2925
3002
  private _evals: Map<string, Promise<unknown>>;
2926
3003
  private _exitListener: (...args: any[]) => void;
2927
3004
  private _fetches: Map<string, Promise<unknown>>;
2928
3005
  private _handleExit(respawn?: boolean, timeout?: number): void;
2929
3006
  private _handleMessage(message: unknown): void;
2930
- private incrementMaxListeners(emitter: Worker | ChildProcess): void;
2931
- private decrementMaxListeners(emitter: Worker | ChildProcess): void;
3007
+ private incrementMaxListeners(emitter: EventEmitter | ChildProcess): void;
3008
+ private decrementMaxListeners(emitter: EventEmitter | ChildProcess): void;
2932
3009
 
2933
3010
  public args: string[];
2934
3011
  public execArgv: string[];
@@ -2950,14 +3027,24 @@ export class Shard extends AsyncEventEmitter<ShardEventTypes> {
2950
3027
  public respawn(options?: { delay?: number; timeout?: number }): Promise<ChildProcess>;
2951
3028
  public send(message: unknown): Promise<Shard>;
2952
3029
  public spawn(timeout?: number): Promise<ChildProcess>;
3030
+
3031
+ public on<Event extends keyof ShardEventTypes>(
3032
+ event: Event,
3033
+ listener: (...args: ShardEventTypes[Event]) => void,
3034
+ ): this;
3035
+
3036
+ public once<Event extends keyof ShardEventTypes>(
3037
+ event: Event,
3038
+ listener: (...args: ShardEventTypes[Event]) => void,
3039
+ ): this;
2953
3040
  }
2954
3041
 
2955
3042
  export class ShardClientUtil {
2956
3043
  private constructor(client: Client<true>, mode: ShardingManagerMode);
2957
3044
  private _handleMessage(message: unknown): void;
2958
3045
  private _respond(type: string, message: unknown): void;
2959
- private incrementMaxListeners(emitter: Worker | ChildProcess): void;
2960
- private decrementMaxListeners(emitter: Worker | ChildProcess): void;
3046
+ private incrementMaxListeners(emitter: EventEmitter | ChildProcess): void;
3047
+ private decrementMaxListeners(emitter: EventEmitter | ChildProcess): void;
2961
3048
 
2962
3049
  public client: Client;
2963
3050
  public get count(): number;
@@ -2986,11 +3073,7 @@ export class ShardClientUtil {
2986
3073
  public static shardIdForGuildId(guildId: Snowflake, shardCount: number): number;
2987
3074
  }
2988
3075
 
2989
- export interface ShardingManagerEvents {
2990
- shardCreate: [shard: Shard];
2991
- }
2992
-
2993
- export class ShardingManager extends AsyncEventEmitter<ShardingManagerEvents> {
3076
+ export class ShardingManager extends EventEmitter {
2994
3077
  public constructor(file: string, options?: ShardingManagerOptions);
2995
3078
  private _performOnShards(method: string, args: readonly unknown[]): Promise<unknown[]>;
2996
3079
  private _performOnShards(method: string, args: readonly unknown[], shard: number): Promise<unknown>;
@@ -3022,6 +3105,10 @@ export class ShardingManager extends AsyncEventEmitter<ShardingManagerEvents> {
3022
3105
  public fetchClientValues(prop: string, shard: number): Promise<unknown>;
3023
3106
  public respawnAll(options?: MultipleShardRespawnOptions): Promise<Collection<number, Shard>>;
3024
3107
  public spawn(options?: MultipleShardSpawnOptions): Promise<Collection<number, Shard>>;
3108
+
3109
+ public on(event: 'shardCreate', listener: (shard: Shard) => void): this;
3110
+
3111
+ public once(event: 'shardCreate', listener: (shard: Shard) => void): this;
3025
3112
  }
3026
3113
 
3027
3114
  export interface FetchRecommendedShardCountOptions {
@@ -3605,8 +3692,8 @@ export class Webhook<Type extends WebhookType = WebhookType> {
3605
3692
  }
3606
3693
 
3607
3694
  // tslint:disable-next-line no-empty-interface
3608
- export interface WebhookClient extends WebhookFields, BaseClient<{}> {}
3609
- export class WebhookClient extends BaseClient<{}> {
3695
+ export interface WebhookClient extends WebhookFields, BaseClient {}
3696
+ export class WebhookClient extends BaseClient {
3610
3697
  public constructor(data: WebhookClientData, options?: WebhookClientOptions);
3611
3698
  public readonly client: this;
3612
3699
  public options: WebhookClientOptions;
@@ -1306,9 +1306,9 @@ client.on('guildCreate', async g => {
1306
1306
  );
1307
1307
  });
1308
1308
 
1309
- // Event emitter static method overrides
1309
+ // EventEmitter static method overrides
1310
1310
  expectType<Promise<[Client<true>]>>(Client.once(client, 'clientReady'));
1311
- expectAssignable<AsyncIterableIterator<[Client<true>]>>(Client.on(client, 'clientReady'));
1311
+ expectType<AsyncIterableIterator<[Client<true>]>>(Client.on(client, 'clientReady'));
1312
1312
 
1313
1313
  client.login('absolutely-valid-token');
1314
1314