Skip to content

Commit d8ea80a

Browse files
author
melike2d
committed
✨ add volume property
1 parent d9f4d56 commit d8ea80a

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/player.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export class Player<N extends Node = Node> extends EventEmitter<PlayerEvents> {
5151
filters: Partial<Lavalink.FilterData> = {};
5252

5353
#_voiceUpdate: Partial<Lavalink.VoiceUpdateData> = {};
54+
#_volume = 100;
5455

5556
constructor(node: N, guildId: bigint) {
5657
super(constants.maxEvents);
@@ -59,6 +60,15 @@ export class Player<N extends Node = Node> extends EventEmitter<PlayerEvents> {
5960
this.guildId = guildId;
6061
}
6162

63+
/**
64+
* The volume of this player.
65+
*/
66+
get volume() {
67+
return constants.useFilters
68+
? (this.filters.volume ?? 1) * 100
69+
: this.#_volume;
70+
}
71+
6272
/**
6373
* Connects to the supplied VC or disconnects from the current VC.
6474
* @param channel ID of the VC to connect to, or null to disconnect.
@@ -160,6 +170,7 @@ export class Player<N extends Node = Node> extends EventEmitter<PlayerEvents> {
160170
guildId: `${this.guildId}`,
161171
position: to,
162172
});
173+
163174
return this;
164175
}
165176

@@ -178,13 +189,12 @@ export class Player<N extends Node = Node> extends EventEmitter<PlayerEvents> {
178189
* @returns the player, useful for chaining?
179190
*/
180191
async setVolume(volume = 100): Promise<this> {
181-
(await constants.useFilters)
182-
? this.setFilters(Lavalink.Filter.Volume, volume > 1 ? volume / 100 : volume)
183-
: this.node.send({
184-
op: "volume",
185-
guildId: `${this.guildId}`,
186-
volume,
187-
});
192+
if (constants.useFilters) {
193+
await this.setFilters(Lavalink.Filter.Volume, volume > 1 ? volume / 100 : volume)
194+
} else {
195+
await this.node.send({ op: "volume", guildId: this.guildId.toString(), volume });
196+
this.#_volume = volume;
197+
}
188198

189199
return this;
190200
}

0 commit comments

Comments
 (0)