move things a bit

This commit is contained in:
Snowflake107 2021-06-12 19:07:45 +05:45
parent 2206d68dfb
commit 1f6e6d1098

View file

@ -92,23 +92,17 @@ class Queue<T = unknown> {
const track = options.filtersUpdate ? this.current : src ?? this.tracks.shift(); const track = options.filtersUpdate ? this.current : src ?? this.tracks.shift();
if (!track) return; if (!track) return;
let resource: AudioResource<Track>; let stream;
if (["youtube", "spotify"].includes(track.raw.source)) { if (["youtube", "spotify"].includes(track.raw.source)) {
const stream = ytdl(track.raw.source === "spotify" ? track.raw.engine : track.url, { stream = ytdl(track.raw.source === "spotify" ? track.raw.engine : track.url, {
// because we don't wanna decode opus into pcm again just for volume, let discord.js handle that // because we don't wanna decode opus into pcm again just for volume, let discord.js handle that
opusEncoded: false, opusEncoded: false,
fmt: "s16le", fmt: "s16le",
encoderArgs: options.encoderArgs ?? [], encoderArgs: options.encoderArgs ?? [],
seek: options.seek seek: options.seek
}); });
resource = this.connection.createStream(stream, {
type: StreamType.Raw,
data: track
});
} else { } else {
const stream = ytdl.arbitraryStream( stream = ytdl.arbitraryStream(
track.raw.source === "soundcloud" track.raw.source === "soundcloud"
? await track.raw.engine.downloadProgressive() ? await track.raw.engine.downloadProgressive()
: (track.raw.engine as string), : (track.raw.engine as string),
@ -120,13 +114,13 @@ class Queue<T = unknown> {
seek: options.seek seek: options.seek
} }
); );
resource = this.connection.createStream(stream, {
type: StreamType.Raw,
data: track
});
} }
const resource: AudioResource<Track> = this.connection.createStream(stream, {
type: StreamType.Raw,
data: track
});
const dispatcher = await this.connection.playStream(resource); const dispatcher = await this.connection.playStream(resource);
dispatcher.setVolume(this.options.initialVolume); dispatcher.setVolume(this.options.initialVolume);