From b7c2eabff5ea2019d12178539c0e1283527c44d2 Mon Sep 17 00:00:00 2001 From: Snowflake107 Date: Mon, 14 Jun 2021 20:29:15 +0545 Subject: [PATCH] some updates --- src/Player.ts | 2 +- src/Structures/Queue.ts | 8 +++++--- src/VoiceInterface/VoiceUtils.ts | 19 +++++++++++++++---- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/Player.ts b/src/Player.ts index 678eb52..230bd3a 100644 --- a/src/Player.ts +++ b/src/Player.ts @@ -97,7 +97,7 @@ class DiscordPlayer extends EventEmitter { const _meta = queueInitOptions.metadata; delete queueInitOptions["metadata"]; - queueInitOptions.ytdlOptions ??= this.options.ytdlOptions + queueInitOptions.ytdlOptions ??= this.options.ytdlOptions; const queue = new Queue(this, guild, queueInitOptions); queue.metadata = _meta; this.queues.set(guild.id, queue); diff --git a/src/Structures/Queue.ts b/src/Structures/Queue.ts index 93fe306..8f7777c 100644 --- a/src/Structures/Queue.ts +++ b/src/Structures/Queue.ts @@ -55,7 +55,9 @@ class Queue { async connect(channel: StageChannel | VoiceChannel) { if (!["stage", "voice"].includes(channel?.type)) throw new TypeError(`Channel type must be voice or stage, got ${channel?.type}!`); - const connection = await this.player.voiceUtils.connect(channel); + const connection = await this.player.voiceUtils.connect(channel, { + deaf: this.options.autoSelfDeaf + }); this.connection = connection; // it's ok to use this here since Queue listens to the events 1 time per play and destroys the listener @@ -149,7 +151,8 @@ class Queue { if (!link) return void this.play(this.tracks.shift(), { immediate: true }); stream = ytdl(link, { - // because we don't wanna decode opus into pcm again just for volume, let discord.js handle that + ...this.options.ytdlOptions, + // discord-ytdl-core opusEncoded: false, fmt: "s16le", encoderArgs: options.encoderArgs ?? [], @@ -159,7 +162,6 @@ class Queue { stream = ytdl.arbitraryStream( track.raw.source === "soundcloud" ? await track.raw.engine.downloadProgressive() : typeof track.raw.engine === "function" ? await track.raw.engine() : track.raw.engine, { - // because we don't wanna decode opus into pcm again just for volume, let discord.js handle that opusEncoded: false, fmt: "s16le", encoderArgs: options.encoderArgs ?? [], diff --git a/src/VoiceInterface/VoiceUtils.ts b/src/VoiceInterface/VoiceUtils.ts index ceb39ef..3fce5fa 100644 --- a/src/VoiceInterface/VoiceUtils.ts +++ b/src/VoiceInterface/VoiceUtils.ts @@ -18,18 +18,29 @@ class VoiceUtils { maxTime?: number; } ): Promise { + const conn = await this.join(channel, options); + const sub = new StreamDispatcher(conn, channel); + this.cache.set(channel.guild.id, sub); + return sub; + } + + public async join( + channel: VoiceChannel | StageChannel, + options?: { + deaf?: boolean; + maxTime?: number; + } + ) { let conn = joinVoiceChannel({ guildId: channel.guild.id, channelId: channel.id, adapterCreator: channel.guild.voiceAdapterCreator, - selfDeaf: Boolean(options?.deaf) + selfDeaf: Boolean(options.deaf) }); try { conn = await entersState(conn, VoiceConnectionStatus.Ready, options?.maxTime ?? 20000); - const sub = new StreamDispatcher(conn, channel); - this.cache.set(channel.guild.id, sub); - return sub; + return conn; } catch (err) { conn.destroy(); throw err;