From 19b3e036348ae9cddd37a37a8618d663d914c44a Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Fri, 2 Feb 2024 16:27:53 -0500 Subject: [PATCH] Persist volume level on player --- src/commands/volume.ts | 2 +- src/services/player.ts | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/commands/volume.ts b/src/commands/volume.ts index e3dd461f..b2515c39 100644 --- a/src/commands/volume.ts +++ b/src/commands/volume.ts @@ -31,7 +31,7 @@ export default class implements Command { const player = this.playerManager.get(interaction.guild!.id); if (!player.canControlVolume()) { - throw new Error('Ope, sorry but I\'m not configured to allow volume control! You can enable it by starting the bot with env VOLUME_CONTROL=true'); + throw new Error('sorry but I\'m not configured to allow volume control! You can enable it by starting the bot with env VOLUME_CONTROL=true'); } const currentSong = player.getCurrent(); diff --git a/src/services/player.ts b/src/services/player.ts index e4ea0f31..27eac199 100644 --- a/src/services/player.ts +++ b/src/services/player.ts @@ -69,6 +69,7 @@ export default class { private queuePosition = 0; private audioPlayer: AudioPlayer | null = null; private audioResource: AudioResource | null = null; + private volume = 100; private nowPlaying: QueuedSong | null = null; private playPositionInterval: NodeJS.Timeout | undefined; private lastSongURL = ''; @@ -406,7 +407,8 @@ export default class { setVolume(level: number): void { // Level should be a number between 0 and 100 = 0% => 100% // Spotify expects a float between 0 and 1 to represent this percentage - this.audioResource?.volume?.setVolume(level / 100); + this.volume = level; + this.audioResource?.volume?.setVolume(this.volume / 100); } getVolume(): number | undefined { @@ -414,7 +416,7 @@ export default class { return undefined; } - return this.audioResource.volume.volume * 100; + return this.volume; } canControlVolume(): boolean { @@ -626,6 +628,7 @@ export default class { private playAudioPlayerResource(resource: AudioResource) { if (this.audioPlayer !== null) { this.audioResource = resource; + this.audioResource?.volume?.setVolume(this.volume / 100); this.audioPlayer.play(resource); } }