From bf2654d002c15b2ba32116cf69c5d37490ec04a2 Mon Sep 17 00:00:00 2001 From: Synbulat Biishev Date: Sat, 22 Jul 2023 20:28:48 +0300 Subject: [PATCH 1/5] feat: add `Client#webhooksUpdate` --- .../src/client/actions/WebhooksUpdate.js | 21 +++++++++++++++++-- packages/discord.js/typings/index.d.ts | 1 + packages/discord.js/typings/index.test-d.ts | 2 +- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/packages/discord.js/src/client/actions/WebhooksUpdate.js b/packages/discord.js/src/client/actions/WebhooksUpdate.js index 914b03fb2f01..b5d0aa428759 100644 --- a/packages/discord.js/src/client/actions/WebhooksUpdate.js +++ b/packages/discord.js/src/client/actions/WebhooksUpdate.js @@ -1,19 +1,36 @@ 'use strict'; +const process = require('node:process'); const Action = require('./Action'); -const Events = require('../../util/Events'); + +let deprecationEmitted = false; class WebhooksUpdate extends Action { handle(data) { const client = this.client; const channel = client.channels.cache.get(data.channel_id); + if (!channel) return; + + // TODO: change to Events.WebhooksUpdate in the next major version + /** + * Emitted whenever a channel has its webhooks changed. + * @event Client#webhooksUpdate + * @param {TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel} channel + * The channel that had a webhook update + */ + client.emit('webhooksUpdate', channel); + /** * Emitted whenever a channel has its webhooks changed. * @event Client#webhookUpdate * @param {TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel} channel * The channel that had a webhook update + * @deprecated Use {@link Client#event:webhooksUpdate} instead */ - if (channel) client.emit(Events.WebhooksUpdate, channel); + if (client.emit('webhookUpdate', channel) && !deprecationEmitted) { + deprecationEmitted = true; + process.emitWarning('The webhookUpdate event is deprecated. Use webhooksUpdate instead', 'DeprecationWarning'); + } } } diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 766ff2deb2be..0429417052e0 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -4862,6 +4862,7 @@ export interface ClientEvents { userUpdate: [oldUser: User | PartialUser, newUser: User]; voiceStateUpdate: [oldState: VoiceState, newState: VoiceState]; webhookUpdate: [channel: TextChannel | NewsChannel | VoiceChannel | ForumChannel]; + webhooksUpdate: [channel: TextChannel | NewsChannel | VoiceChannel | ForumChannel]; interactionCreate: [interaction: Interaction]; shardDisconnect: [closeEvent: CloseEvent, shardId: number]; shardError: [error: Error, shardId: number]; diff --git a/packages/discord.js/typings/index.test-d.ts b/packages/discord.js/typings/index.test-d.ts index 9c9f79938d44..ddcdb1114773 100644 --- a/packages/discord.js/typings/index.test-d.ts +++ b/packages/discord.js/typings/index.test-d.ts @@ -1170,7 +1170,7 @@ client.on('voiceStateUpdate', ({ client: oldClient }, { client: newClient }) => expectType>(newClient); }); -client.on('webhookUpdate', ({ client }) => expectType>(client)); +client.on('webhooksUpdate', ({ client }) => expectType>(client)); client.on('guildCreate', async g => { expectType>(g.client); From 038e8e49fecb3d3e1706c0bca1c3768f5056d45e Mon Sep 17 00:00:00 2001 From: Synbulat Biishev Date: Sat, 22 Jul 2023 20:39:36 +0300 Subject: [PATCH 2/5] feat: add deprecation in the types --- packages/discord.js/typings/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 0429417052e0..b363c045bd20 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -4861,6 +4861,7 @@ export interface ClientEvents { typingStart: [typing: Typing]; userUpdate: [oldUser: User | PartialUser, newUser: User]; voiceStateUpdate: [oldState: VoiceState, newState: VoiceState]; + /** @deprecated Use {@link Client#event:webhooksUpdate} instead */ webhookUpdate: [channel: TextChannel | NewsChannel | VoiceChannel | ForumChannel]; webhooksUpdate: [channel: TextChannel | NewsChannel | VoiceChannel | ForumChannel]; interactionCreate: [interaction: Interaction]; From cba20a455e171e1a08ea48d548eb2355d5798781 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Wed, 9 Aug 2023 14:56:32 +0100 Subject: [PATCH 3/5] docs: add full stops --- packages/discord.js/src/client/actions/WebhooksUpdate.js | 4 ++-- packages/discord.js/typings/index.d.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/discord.js/src/client/actions/WebhooksUpdate.js b/packages/discord.js/src/client/actions/WebhooksUpdate.js index b5d0aa428759..2bf41ba2702f 100644 --- a/packages/discord.js/src/client/actions/WebhooksUpdate.js +++ b/packages/discord.js/src/client/actions/WebhooksUpdate.js @@ -25,11 +25,11 @@ class WebhooksUpdate extends Action { * @event Client#webhookUpdate * @param {TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel} channel * The channel that had a webhook update - * @deprecated Use {@link Client#event:webhooksUpdate} instead + * @deprecated Use {@link Client#event:webhooksUpdate} instead. */ if (client.emit('webhookUpdate', channel) && !deprecationEmitted) { deprecationEmitted = true; - process.emitWarning('The webhookUpdate event is deprecated. Use webhooksUpdate instead', 'DeprecationWarning'); + process.emitWarning('The webhookUpdate event is deprecated. Use webhooksUpdate instead.', 'DeprecationWarning'); } } } diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index b363c045bd20..be4d2004eced 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -4861,7 +4861,7 @@ export interface ClientEvents { typingStart: [typing: Typing]; userUpdate: [oldUser: User | PartialUser, newUser: User]; voiceStateUpdate: [oldState: VoiceState, newState: VoiceState]; - /** @deprecated Use {@link Client#event:webhooksUpdate} instead */ + /** @deprecated Use {@link Client#event:webhooksUpdate} instead. */ webhookUpdate: [channel: TextChannel | NewsChannel | VoiceChannel | ForumChannel]; webhooksUpdate: [channel: TextChannel | NewsChannel | VoiceChannel | ForumChannel]; interactionCreate: [interaction: Interaction]; From cd5c57285d2484f9b5f0c6614dd5decdf424551d Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Wed, 9 Aug 2023 15:07:33 +0100 Subject: [PATCH 4/5] types: reference non-deprecated type This helps with future-proofing (deduplication). --- packages/discord.js/typings/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index be4d2004eced..432d1f44779f 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -4862,7 +4862,7 @@ export interface ClientEvents { userUpdate: [oldUser: User | PartialUser, newUser: User]; voiceStateUpdate: [oldState: VoiceState, newState: VoiceState]; /** @deprecated Use {@link Client#event:webhooksUpdate} instead. */ - webhookUpdate: [channel: TextChannel | NewsChannel | VoiceChannel | ForumChannel]; + webhookUpdate: ClientEvents['webhooksUpdate']; webhooksUpdate: [channel: TextChannel | NewsChannel | VoiceChannel | ForumChannel]; interactionCreate: [interaction: Interaction]; shardDisconnect: [closeEvent: CloseEvent, shardId: number]; From bf91d65600f4dcbb0f6a5a05d70bff2ab05d9fc1 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Wed, 9 Aug 2023 15:08:22 +0100 Subject: [PATCH 5/5] docs(ClientEvents): fix reference link This now hyperlinks correctly with IntelliSense. --- packages/discord.js/typings/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 432d1f44779f..192881db9894 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -4861,7 +4861,7 @@ export interface ClientEvents { typingStart: [typing: Typing]; userUpdate: [oldUser: User | PartialUser, newUser: User]; voiceStateUpdate: [oldState: VoiceState, newState: VoiceState]; - /** @deprecated Use {@link Client#event:webhooksUpdate} instead. */ + /** @deprecated Use {@link webhooksUpdate} instead. */ webhookUpdate: ClientEvents['webhooksUpdate']; webhooksUpdate: [channel: TextChannel | NewsChannel | VoiceChannel | ForumChannel]; interactionCreate: [interaction: Interaction];