Skip to content

Commit

Permalink
feat(player): add option allowSwitchChannels
Browse files Browse the repository at this point in the history
  • Loading branch information
larsrickert committed Jun 18, 2022
1 parent cfbf93e commit 9bceb75
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ export class Player extends TypedEmitter<PlayerEvents> {
* registers events when disconnected and destroyed.
*/
private join(channel: VoiceBasedChannel): VoiceConnection {
// check if player is allowed to switch channels when already playing in another voice channel
if (!(this.options.allowSwitchChannels ?? true)) {
const currentConnection = getVoiceConnection(channel.guildId);
if (
currentConnection &&
currentConnection.joinConfig.channelId !== channel.id
) {
throw new Error(
"Refused to join voice channel because player is already connected to another voice channel"
);
}
}

const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
Expand Down
10 changes: 9 additions & 1 deletion src/types/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface PlayerOptions {
* Setting to `true` will enable the player to change the volume of the played tracks.
* Set to `false` for slightly better performance.
*
* @default `true`
* @default true
*/
inlineVolume?: boolean;
/** Initial player volume for all tracks between 0 and 200. */
Expand All @@ -62,6 +62,14 @@ export interface PlayerOptions {
fileRoot?: string;
/** Custom player engines to provide additional streaming services or override existing ones. */
customEngines?: Record<string, PlayerEngine>;
/**
* When `true` and the player is already playing in voice channel A, player will be allowed to switch to
* voice channel B. If `false`, player wont connect to another voice channel when he is already playing in a voice channel.
*
* @default true
*
*/
allowSwitchChannels?: boolean;
}

export interface AudioPlayerMetadata {
Expand Down

0 comments on commit 9bceb75

Please sign in to comment.