Skip to content

Joining and Leaving

nutmeg edited this page Feb 22, 2023 · 4 revisions

Run Down

Joining and leaving voice channels in Discord+PS is extremely simple compared to Discord.JS
For example, here's how to join a voice channel using Discord+PS:

PSClient.voice.join(channel);

And here's how to join a voice channel in the current version of Discord.JS as of writing this:

voice.joinVoiceChannel({
	channelId: channel.id,
    guildId: channel.guild.id,
    adapterCreator: channel.guild.voiceAdapterCreator
});

Joining

Joining is very similar to how Discord.JS was before

// discord.js
channel.join();

Though modified to work for the new version and with the PSClient
Join is called with PSClient.voice.join(channel) as you can see here in this example where it finds where a user is then joins their voice channel:

PSClient.voice.find(user, (channel) => {
	PSClient.voice.join(channel);
	console.log(`Joined ${channel.name}`;
});

Leaving

Leaving is pretty simple to use only requiring a channel

PSClient.voice.leave(channel);

// or

PSClient.voice.disconnect(channel);

Here's the code for leaving if you want it:

leave(channel) {
	const connection = voice.getVoiceConnection(channel.guild.id);
	try {
		connection.destroy();
	} catch(err) {
		throw new CoolError("Leaving Voice Channel", "Not in channel or cannot leave.");
	}
}
Clone this wiki locally