mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 04:23:31 +01:00
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>
This commit is contained in:
@@ -1,19 +1,36 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const process = require('node:process');
|
||||||
const Action = require('./Action');
|
const Action = require('./Action');
|
||||||
const Events = require('../../util/Events');
|
|
||||||
|
let deprecationEmitted = false;
|
||||||
|
|
||||||
class WebhooksUpdate extends Action {
|
class WebhooksUpdate extends Action {
|
||||||
handle(data) {
|
handle(data) {
|
||||||
const client = this.client;
|
const client = this.client;
|
||||||
const channel = client.channels.cache.get(data.channel_id);
|
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.
|
* Emitted whenever a channel has its webhooks changed.
|
||||||
* @event Client#webhookUpdate
|
* @event Client#webhookUpdate
|
||||||
* @param {TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel} channel
|
* @param {TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel} channel
|
||||||
* The channel that had a webhook update
|
* 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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
4
packages/discord.js/typings/index.d.ts
vendored
4
packages/discord.js/typings/index.d.ts
vendored
@@ -4861,7 +4861,9 @@ export interface ClientEvents {
|
|||||||
typingStart: [typing: Typing];
|
typingStart: [typing: Typing];
|
||||||
userUpdate: [oldUser: User | PartialUser, newUser: User];
|
userUpdate: [oldUser: User | PartialUser, newUser: User];
|
||||||
voiceStateUpdate: [oldState: VoiceState, newState: VoiceState];
|
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];
|
interactionCreate: [interaction: Interaction];
|
||||||
shardDisconnect: [closeEvent: CloseEvent, shardId: number];
|
shardDisconnect: [closeEvent: CloseEvent, shardId: number];
|
||||||
shardError: [error: Error, shardId: number];
|
shardError: [error: Error, shardId: number];
|
||||||
|
|||||||
@@ -1170,7 +1170,7 @@ client.on('voiceStateUpdate', ({ client: oldClient }, { client: newClient }) =>
|
|||||||
expectType<Client<true>>(newClient);
|
expectType<Client<true>>(newClient);
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('webhookUpdate', ({ client }) => expectType<Client<true>>(client));
|
client.on('webhooksUpdate', ({ client }) => expectType<Client<true>>(client));
|
||||||
|
|
||||||
client.on('guildCreate', async g => {
|
client.on('guildCreate', async g => {
|
||||||
expectType<Client<true>>(g.client);
|
expectType<Client<true>>(g.client);
|
||||||
|
|||||||
Reference in New Issue
Block a user