diff --git a/packages/discord.js/src/client/actions/VoiceStateUpdate.js b/packages/discord.js/src/client/actions/VoiceStateUpdate.js index fc7400f2e..a091067b2 100644 --- a/packages/discord.js/src/client/actions/VoiceStateUpdate.js +++ b/packages/discord.js/src/client/actions/VoiceStateUpdate.js @@ -25,7 +25,7 @@ class VoiceStateUpdate extends Action { // Emit event if (member?.user.id === client.user.id) { - client.emit('debug', `[VOICE] received voice state update: ${JSON.stringify(data)}`); + client.emit(Events.Debug, `[VOICE] received voice state update: ${JSON.stringify(data)}`); client.voice.onVoiceStateUpdate(data); } diff --git a/packages/discord.js/src/client/websocket/handlers/VOICE_SERVER_UPDATE.js b/packages/discord.js/src/client/websocket/handlers/VOICE_SERVER_UPDATE.js index f9cf53433..828656ee2 100644 --- a/packages/discord.js/src/client/websocket/handlers/VOICE_SERVER_UPDATE.js +++ b/packages/discord.js/src/client/websocket/handlers/VOICE_SERVER_UPDATE.js @@ -1,6 +1,33 @@ 'use strict'; -module.exports = (client, packet) => { - client.emit('debug', `[VOICE] received voice server: ${JSON.stringify(packet)}`); - client.voice.onVoiceServer(packet.d); +const Events = require('../../../util/Events'); + +module.exports = (client, { d: data }) => { + client.emit( + Events.Debug, + `[VOICE] received voice server: ${JSON.stringify({ ...data, token: '*'.repeat(data.token.length) })}`, + ); + + client.voice.onVoiceServer(data); + + /** + * Represents the properties of a voice server update + * + * @typedef {Object} VoiceServerUpdateData + * @property {Snowflake} guildId The id of the guild this voice server update is for + * @property {?string} endpoint The voice server host + * @property {string} token The voice connection token + */ + + /** + * Emitted whenever a voice server is updated. + * + * @event Client#voiceServerUpdate + * @param {VoiceServerUpdateData} data The voice server update data + */ + client.emit(Events.VoiceServerUpdate, { + guildId: data.guild_id, + endpoint: data.endpoint, + token: data.token, + }); }; diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 2fc0154ff..de1ade0d6 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -6073,6 +6073,12 @@ export type OmitPartialGroupDMChannel = channel: Exclude; }; +export interface VoiceServerUpdateData { + endpoint: string | null; + guildId: Snowflake; + token: string; +} + export interface ClientEvents { applicationCommandPermissionsUpdate: [data: ApplicationCommandPermissionsUpdateData]; autoModerationActionExecution: [autoModerationActionExecution: AutoModerationActionExecution]; @@ -6170,6 +6176,7 @@ export interface ClientEvents { typingStart: [typing: Typing]; userUpdate: [oldUser: User | PartialUser, newUser: User]; voiceChannelEffectSend: [voiceChannelEffect: VoiceChannelEffect]; + voiceServerUpdate: [data: VoiceServerUpdateData]; voiceStateUpdate: [oldState: VoiceState, newState: VoiceState]; /** @deprecated Use {@link ClientEvents.webhooksUpdate} instead. */ webhookUpdate: ClientEvents['webhooksUpdate']; diff --git a/packages/discord.js/typings/index.test-d.ts b/packages/discord.js/typings/index.test-d.ts index d3c5111a5..5d5d55a87 100644 --- a/packages/discord.js/typings/index.test-d.ts +++ b/packages/discord.js/typings/index.test-d.ts @@ -202,6 +202,7 @@ import { Entitlement, SKU, UserSelectMenuBuilder, + VoiceServerUpdateData, RoleSelectMenuBuilder, ChannelSelectMenuBuilder, MentionableSelectMenuBuilder, @@ -1357,6 +1358,10 @@ client.on('userUpdate', ({ client: oldClient }, { client: newClient }) => { expectType>(newClient); }); +client.on('voiceServerUpdate', data => { + expectType(data); +}); + client.on('voiceStateUpdate', ({ client: oldClient }, { client: newClient }) => { expectType>(oldClient); expectType>(newClient);