PlayerVoiceState
Class representing the voice connection and state of a player.
Signature
export declare class PlayerVoiceStateJSDoc
Properties
5Methods
11Properties
endpoint: string | null;The voice server endpoint.
sessionId: string | null;The voice session id.
token: string | null;The voice server token.
channelId: string | null;The voice channel id.
readonly player: PlayerStructure;Reference to the player structure this voice instance belongs to.
Methods
constructorConstructorconstructor(player: PlayerStructure);patch(data: VoiceDataUpdate): this;Merge voice data from Lavalink or gateway updates.
Parameters
data- The partial voice data to update with.
Returns
The current PlayerVoiceState instance after patching.
Examples
const player = manager.getPlayer("guildId");
if (player) {
player.voice.patch({
sessionId: "session-id",
channelId: "voice-channel-id",
});
}reset(): this;Reset all voice connection values.
Returns
The current PlayerVoiceState instance.
Examples
const player = manager.getPlayer("guildId");
if (player) {
player.voice.reset();
}toJSON(): Nullable<LavalinkPlayerVoice>;Return the current voice values as a nullable payload.
Returns
The current voice data as a nullable LavalinkPlayerVoice payload.
Examples
const player = manager.getPlayer("guildId");
if (player) {
const voice = player.voice.toJSON();
console.log(voice.endpoint);
}toNode(): LavalinkPlayerVoice | null;Return a valid Lavalink voice payload when all required fields are present.
Returns
The Lavalink voice payload or null if required fields are missing.
Examples
const player = manager.getPlayer("guildId");
if (player) {
const voice = player.voice.toNode();
if (!voice) console.log("Voice payload is incomplete");
}setState(options?: NullableVoiceChannelUpdate): Promise<void>;Send a voice state payload to the Discord gateway.
Parameters
options- The voice state options to update. Only include fields that need to be updated, others will be kept as is.
Examples
const player = manager.getPlayer("guildId");
if (player) {
await player.voice.setState({
voiceId: "new-voice-channel-id",
selfMute: false,
});
}connect(): Promise<void>;Connect the player to its configured voice channel.
Examples
const player = manager.getPlayer("guildId");
if (player) {
await player.voice.connect();
}disconnect(): Promise<void>;Disconnect the player from voice.
Returns
Examples
const player = manager.getPlayer("guildId");
if (player) {
await player.voice.disconnect();
}move(voiceId: string): Promise<PlayerStructure>;Move the player to another voice channel.
Parameters
voiceId- The id of the voice channel to move to.
Returns
The player structure after moving.
Examples
const player = manager.getPlayer("guildId");
if (player) {
await player.voice.move("target-voice-channel-id");
}mute(selfMute?: boolean): Promise<PlayerStructure>;Toggle or set self mute.
Parameters
selfMute- Whether to self mute or not. Defaults to toggling the current state.
Returns
The player structure after updating mute state.
Examples
const player = manager.getPlayer("guildId");
if (player) {
await player.voice.mute(true);
}deaf(selfDeaf?: boolean): Promise<PlayerStructure>;Toggle or set self deaf.
Parameters
selfDeaf- Whether to self deafen or not. Defaults to toggling the current state.
Returns
The player structure after updating deafen state.
Examples
const player = manager.getPlayer("guildId");
if (player) {
await player.voice.deaf(true);
}