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..e4d76b71a 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.js'); + +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/src/client/websocket/handlers/VOICE_STATE_UPDATE.js b/packages/discord.js/src/client/websocket/handlers/VOICE_STATE_UPDATE.js index fdbc5078c..8557d6813 100644 --- a/packages/discord.js/src/client/websocket/handlers/VOICE_STATE_UPDATE.js +++ b/packages/discord.js/src/client/websocket/handlers/VOICE_STATE_UPDATE.js @@ -23,7 +23,7 @@ module.exports = (client, { d: data }) => { // 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/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 8db068601..655f09385 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -5458,6 +5458,12 @@ export type OmitPartialGroupDMChannel = channel: Exclude; }; +export interface VoiceServerUpdateData { + endpoint: string | null; + guildId: Snowflake; + token: string; +} + export interface ClientEventTypes { applicationCommandPermissionsUpdate: [data: ApplicationCommandPermissionsUpdateData]; autoModerationActionExecution: [autoModerationActionExecution: AutoModerationActionExecution]; @@ -5571,6 +5577,7 @@ export interface ClientEventTypes { typingStart: [typing: Typing]; userUpdate: [oldUser: PartialUser | User, newUser: User]; voiceChannelEffectSend: [voiceChannelEffect: VoiceChannelEffect]; + voiceServerUpdate: [data: VoiceServerUpdateData]; voiceStateUpdate: [oldState: VoiceState, newState: VoiceState]; warn: [message: string]; webhooksUpdate: [channel: AnnouncementChannel | ForumChannel | MediaChannel | TextChannel | VoiceChannel]; diff --git a/packages/discord.js/typings/index.test-d.ts b/packages/discord.js/typings/index.test-d.ts index 86d8b5760..578ecce1a 100644 --- a/packages/discord.js/typings/index.test-d.ts +++ b/packages/discord.js/typings/index.test-d.ts @@ -202,6 +202,7 @@ import type { Invite, GuildInvite, AuthorizingIntegrationOwners, + VoiceServerUpdateData, } from './index.js'; import { ActionRowBuilder, @@ -1379,6 +1380,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);