Skip to content

Commit

Permalink
fix: volume glitch when async function is used for initial volume
Browse files Browse the repository at this point in the history
  • Loading branch information
larsrickert committed Jun 18, 2022
1 parent 898d791 commit 9f802bf
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,24 +187,28 @@ export class Player extends TypedEmitter<PlayerEvents> {
}
}

this.audioResource = createAudioResource(trackStream.stream, {
inputType: trackStream.type,
inlineVolume,
metadata,
});
// get (initial) player volume
let volume: number;

// set player volume
if (this.volume != null) {
this.setVolume(this.volume);
volume = this.volume;
} else {
const initialVolume =
typeof this.options.initialVolume === "function"
? await this.options.initialVolume(options.channel.guildId)
: this.options.initialVolume;

this.setVolume(initialVolume ?? 100);
volume = initialVolume ?? 100;
}

this.audioResource = createAudioResource(trackStream.stream, {
inputType: trackStream.type,
inlineVolume,
metadata,
});

this.setVolume(volume);

this.join(options.channel);
this.audioPlayer.play(this.audioResource);

Expand Down

0 comments on commit 9f802bf

Please sign in to comment.