From 0de071d0a5524ba1fbb8cab5d7e74567103f7129 Mon Sep 17 00:00:00 2001 From: Synbulat Biishev Date: Wed, 9 Aug 2023 19:15:00 +0500 Subject: [PATCH] feat: add `Client#webhooksUpdate` (#9732) * feat: add `Client#webhooksUpdate` * feat: add deprecation in the types * docs: add full stops * types: reference non-deprecated type This helps with future-proofing (deduplication). * docs(ClientEvents): fix reference link This now hyperlinks correctly with IntelliSense. --------- Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../src/client/actions/WebhooksUpdate.js | 21 +++++++++++++++++-- packages/discord.js/typings/index.d.ts | 4 +++- packages/discord.js/typings/index.test-d.ts | 2 +- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/packages/discord.js/src/client/actions/WebhooksUpdate.js b/packages/discord.js/src/client/actions/WebhooksUpdate.js index 914b03fb2..2bf41ba27 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 766ff2deb..192881db9 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -4861,7 +4861,9 @@ export interface ClientEvents { typingStart: [typing: Typing]; userUpdate: [oldUser: User | PartialUser, newUser: User]; voiceStateUpdate: [oldState: VoiceState, newState: VoiceState]; - webhookUpdate: [channel: TextChannel | NewsChannel | VoiceChannel | ForumChannel]; + /** @deprecated Use {@link webhooksUpdate} instead. */ + webhookUpdate: ClientEvents['webhooksUpdate']; + 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 9c9f79938..ddcdb1114 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);