some updates
This commit is contained in:
parent
7f73e02a60
commit
b7c2eabff5
3 changed files with 21 additions and 8 deletions
|
@ -97,7 +97,7 @@ class DiscordPlayer extends EventEmitter<PlayerEvents> {
|
|||
|
||||
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);
|
||||
|
|
|
@ -55,7 +55,9 @@ class Queue<T = unknown> {
|
|||
|
||||
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<T = unknown> {
|
|||
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<T = unknown> {
|
|||
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 ?? [],
|
||||
|
|
|
@ -18,18 +18,29 @@ class VoiceUtils {
|
|||
maxTime?: number;
|
||||
}
|
||||
): Promise<StreamDispatcher> {
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue