mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 04:23:31 +01:00
types(Events): rest events can be emitted on BaseClient (#6936)
This commit is contained in:
@@ -73,3 +73,9 @@ class BaseClient extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = BaseClient;
|
module.exports = BaseClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted for general debugging information.
|
||||||
|
* @event BaseClient#debug
|
||||||
|
* @param {string} info The debug information
|
||||||
|
*/
|
||||||
|
|||||||
@@ -605,12 +605,6 @@ module.exports = Client;
|
|||||||
* @param {string} info The warning
|
* @param {string} info The warning
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* Emitted for general debugging information.
|
|
||||||
* @event Client#debug
|
|
||||||
* @param {string} info The debug information
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @external Collection
|
* @external Collection
|
||||||
* @see {@link https://discord.js.org/#/docs/collection/main/class/Collection}
|
* @see {@link https://discord.js.org/#/docs/collection/main/class/Collection}
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ class RequestHandler {
|
|||||||
if (this.manager.client.listenerCount(RATE_LIMIT)) {
|
if (this.manager.client.listenerCount(RATE_LIMIT)) {
|
||||||
/**
|
/**
|
||||||
* Emitted when the client hits a rate limit while making a request
|
* Emitted when the client hits a rate limit while making a request
|
||||||
* @event Client#rateLimit
|
* @event BaseClient#rateLimit
|
||||||
* @param {RateLimitData} rateLimitData Object containing the rate limit info
|
* @param {RateLimitData} rateLimitData Object containing the rate limit info
|
||||||
*/
|
*/
|
||||||
this.manager.client.emit(RATE_LIMIT, {
|
this.manager.client.emit(RATE_LIMIT, {
|
||||||
@@ -178,7 +178,7 @@ class RequestHandler {
|
|||||||
* This event can emit several times for the same request, e.g. when hitting a rate limit.
|
* This event can emit several times for the same request, e.g. when hitting a rate limit.
|
||||||
* <info>This is an informational event that is emitted quite frequently,
|
* <info>This is an informational event that is emitted quite frequently,
|
||||||
* it is highly recommended to check `request.path` to filter the data.</info>
|
* it is highly recommended to check `request.path` to filter the data.</info>
|
||||||
* @event Client#apiRequest
|
* @event BaseClient#apiRequest
|
||||||
* @param {APIRequest} request The request that is about to be sent
|
* @param {APIRequest} request The request that is about to be sent
|
||||||
*/
|
*/
|
||||||
this.manager.client.emit(API_REQUEST, {
|
this.manager.client.emit(API_REQUEST, {
|
||||||
@@ -210,7 +210,7 @@ class RequestHandler {
|
|||||||
* This event does not necessarily correlate to completion of the request, e.g. when hitting a rate limit.
|
* This event does not necessarily correlate to completion of the request, e.g. when hitting a rate limit.
|
||||||
* <info>This is an informational event that is emitted quite frequently,
|
* <info>This is an informational event that is emitted quite frequently,
|
||||||
* it is highly recommended to check `request.path` to filter the data.</info>
|
* it is highly recommended to check `request.path` to filter the data.</info>
|
||||||
* @event Client#apiResponse
|
* @event BaseClient#apiResponse
|
||||||
* @param {APIRequest} request The request that triggered this response
|
* @param {APIRequest} request The request that triggered this response
|
||||||
* @param {Response} response The response received from the Discord API
|
* @param {Response} response The response received from the Discord API
|
||||||
*/
|
*/
|
||||||
@@ -285,7 +285,7 @@ class RequestHandler {
|
|||||||
/**
|
/**
|
||||||
* Emitted periodically when the process sends invalid requests to let users avoid the
|
* Emitted periodically when the process sends invalid requests to let users avoid the
|
||||||
* 10k invalid requests in 10 minutes threshold that causes a ban
|
* 10k invalid requests in 10 minutes threshold that causes a ban
|
||||||
* @event Client#invalidRequestWarning
|
* @event BaseClient#invalidRequestWarning
|
||||||
* @param {InvalidRequestWarningData} invalidRequestWarningData Object containing the invalid request info
|
* @param {InvalidRequestWarningData} invalidRequestWarningData Object containing the invalid request info
|
||||||
*/
|
*/
|
||||||
this.manager.client.emit(INVALID_REQUEST_WARNING, {
|
this.manager.client.emit(INVALID_REQUEST_WARNING, {
|
||||||
|
|||||||
44
typings/index.d.ts
vendored
44
typings/index.d.ts
vendored
@@ -265,6 +265,39 @@ export class BaseClient extends EventEmitter {
|
|||||||
private decrementMaxListeners(): void;
|
private decrementMaxListeners(): void;
|
||||||
private incrementMaxListeners(): void;
|
private incrementMaxListeners(): void;
|
||||||
|
|
||||||
|
public on<K extends keyof BaseClientEvents>(
|
||||||
|
event: K,
|
||||||
|
listener: (...args: BaseClientEvents[K]) => Awaitable<void>,
|
||||||
|
): this;
|
||||||
|
public on<S extends string | symbol>(
|
||||||
|
event: Exclude<S, keyof BaseClientEvents>,
|
||||||
|
listener: (...args: any[]) => Awaitable<void>,
|
||||||
|
): this;
|
||||||
|
|
||||||
|
public once<K extends keyof BaseClientEvents>(
|
||||||
|
event: K,
|
||||||
|
listener: (...args: BaseClientEvents[K]) => Awaitable<void>,
|
||||||
|
): this;
|
||||||
|
public once<S extends string | symbol>(
|
||||||
|
event: Exclude<S, keyof BaseClientEvents>,
|
||||||
|
listener: (...args: any[]) => Awaitable<void>,
|
||||||
|
): this;
|
||||||
|
|
||||||
|
public emit<K extends keyof BaseClientEvents>(event: K, ...args: BaseClientEvents[K]): boolean;
|
||||||
|
public emit<S extends string | symbol>(event: Exclude<S, keyof BaseClientEvents>, ...args: unknown[]): boolean;
|
||||||
|
|
||||||
|
public off<K extends keyof BaseClientEvents>(
|
||||||
|
event: K,
|
||||||
|
listener: (...args: BaseClientEvents[K]) => Awaitable<void>,
|
||||||
|
): this;
|
||||||
|
public off<S extends string | symbol>(
|
||||||
|
event: Exclude<S, keyof BaseClientEvents>,
|
||||||
|
listener: (...args: any[]) => Awaitable<void>,
|
||||||
|
): this;
|
||||||
|
|
||||||
|
public removeAllListeners<K extends keyof BaseClientEvents>(event?: K): this;
|
||||||
|
public removeAllListeners<S extends string | symbol>(event?: Exclude<S, keyof BaseClientEvents>): this;
|
||||||
|
|
||||||
public options: ClientOptions | WebhookClientOptions;
|
public options: ClientOptions | WebhookClientOptions;
|
||||||
public destroy(): void;
|
public destroy(): void;
|
||||||
public toJSON(...props: Record<string, boolean | string>[]): unknown;
|
public toJSON(...props: Record<string, boolean | string>[]): unknown;
|
||||||
@@ -3553,9 +3586,15 @@ export interface ChannelWebhookCreateOptions {
|
|||||||
reason?: string;
|
reason?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ClientEvents {
|
export interface BaseClientEvents {
|
||||||
apiResponse: [request: APIRequest, response: Response];
|
apiResponse: [request: APIRequest, response: Response];
|
||||||
apiRequest: [request: APIRequest];
|
apiRequest: [request: APIRequest];
|
||||||
|
debug: [message: string];
|
||||||
|
rateLimit: [rateLimitData: RateLimitData];
|
||||||
|
invalidRequestWarning: [invalidRequestWarningData: InvalidRequestWarningData];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ClientEvents extends BaseClientEvents {
|
||||||
/** @deprecated See [this issue](https://github.com/discord/discord-api-docs/issues/3690) for more information. */
|
/** @deprecated See [this issue](https://github.com/discord/discord-api-docs/issues/3690) for more information. */
|
||||||
applicationCommandCreate: [command: ApplicationCommand];
|
applicationCommandCreate: [command: ApplicationCommand];
|
||||||
/** @deprecated See [this issue](https://github.com/discord/discord-api-docs/issues/3690) for more information. */
|
/** @deprecated See [this issue](https://github.com/discord/discord-api-docs/issues/3690) for more information. */
|
||||||
@@ -3566,7 +3605,6 @@ export interface ClientEvents {
|
|||||||
channelDelete: [channel: DMChannel | GuildChannel];
|
channelDelete: [channel: DMChannel | GuildChannel];
|
||||||
channelPinsUpdate: [channel: TextBasedChannels, date: Date];
|
channelPinsUpdate: [channel: TextBasedChannels, date: Date];
|
||||||
channelUpdate: [oldChannel: DMChannel | GuildChannel, newChannel: DMChannel | GuildChannel];
|
channelUpdate: [oldChannel: DMChannel | GuildChannel, newChannel: DMChannel | GuildChannel];
|
||||||
debug: [message: string];
|
|
||||||
warn: [message: string];
|
warn: [message: string];
|
||||||
emojiCreate: [emoji: GuildEmoji];
|
emojiCreate: [emoji: GuildEmoji];
|
||||||
emojiDelete: [emoji: GuildEmoji];
|
emojiDelete: [emoji: GuildEmoji];
|
||||||
@@ -3604,8 +3642,6 @@ export interface ClientEvents {
|
|||||||
messageReactionRemove: [reaction: MessageReaction | PartialMessageReaction, user: User | PartialUser];
|
messageReactionRemove: [reaction: MessageReaction | PartialMessageReaction, user: User | PartialUser];
|
||||||
messageUpdate: [oldMessage: Message | PartialMessage, newMessage: Message | PartialMessage];
|
messageUpdate: [oldMessage: Message | PartialMessage, newMessage: Message | PartialMessage];
|
||||||
presenceUpdate: [oldPresence: Presence | null, newPresence: Presence];
|
presenceUpdate: [oldPresence: Presence | null, newPresence: Presence];
|
||||||
rateLimit: [rateLimitData: RateLimitData];
|
|
||||||
invalidRequestWarning: [invalidRequestWarningData: InvalidRequestWarningData];
|
|
||||||
ready: [client: Client<true>];
|
ready: [client: Client<true>];
|
||||||
invalidated: [];
|
invalidated: [];
|
||||||
roleCreate: [role: Role];
|
roleCreate: [role: Role];
|
||||||
|
|||||||
Reference in New Issue
Block a user