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;
|
const _meta = queueInitOptions.metadata;
|
||||||
delete queueInitOptions["metadata"];
|
delete queueInitOptions["metadata"];
|
||||||
queueInitOptions.ytdlOptions ??= this.options.ytdlOptions
|
queueInitOptions.ytdlOptions ??= this.options.ytdlOptions;
|
||||||
const queue = new Queue(this, guild, queueInitOptions);
|
const queue = new Queue(this, guild, queueInitOptions);
|
||||||
queue.metadata = _meta;
|
queue.metadata = _meta;
|
||||||
this.queues.set(guild.id, queue);
|
this.queues.set(guild.id, queue);
|
||||||
|
|
|
@ -55,7 +55,9 @@ class Queue<T = unknown> {
|
||||||
|
|
||||||
async connect(channel: StageChannel | VoiceChannel) {
|
async connect(channel: StageChannel | VoiceChannel) {
|
||||||
if (!["stage", "voice"].includes(channel?.type)) throw new TypeError(`Channel type must be voice or stage, got ${channel?.type}!`);
|
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;
|
this.connection = connection;
|
||||||
|
|
||||||
// it's ok to use this here since Queue listens to the events 1 time per play and destroys the listener
|
// 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 });
|
if (!link) return void this.play(this.tracks.shift(), { immediate: true });
|
||||||
|
|
||||||
stream = ytdl(link, {
|
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,
|
opusEncoded: false,
|
||||||
fmt: "s16le",
|
fmt: "s16le",
|
||||||
encoderArgs: options.encoderArgs ?? [],
|
encoderArgs: options.encoderArgs ?? [],
|
||||||
|
@ -159,7 +162,6 @@ class Queue<T = unknown> {
|
||||||
stream = ytdl.arbitraryStream(
|
stream = ytdl.arbitraryStream(
|
||||||
track.raw.source === "soundcloud" ? await track.raw.engine.downloadProgressive() : typeof track.raw.engine === "function" ? await track.raw.engine() : track.raw.engine,
|
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,
|
opusEncoded: false,
|
||||||
fmt: "s16le",
|
fmt: "s16le",
|
||||||
encoderArgs: options.encoderArgs ?? [],
|
encoderArgs: options.encoderArgs ?? [],
|
||||||
|
|
|
@ -18,18 +18,29 @@ class VoiceUtils {
|
||||||
maxTime?: number;
|
maxTime?: number;
|
||||||
}
|
}
|
||||||
): Promise<StreamDispatcher> {
|
): 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({
|
let conn = joinVoiceChannel({
|
||||||
guildId: channel.guild.id,
|
guildId: channel.guild.id,
|
||||||
channelId: channel.id,
|
channelId: channel.id,
|
||||||
adapterCreator: channel.guild.voiceAdapterCreator,
|
adapterCreator: channel.guild.voiceAdapterCreator,
|
||||||
selfDeaf: Boolean(options?.deaf)
|
selfDeaf: Boolean(options.deaf)
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
conn = await entersState(conn, VoiceConnectionStatus.Ready, options?.maxTime ?? 20000);
|
conn = await entersState(conn, VoiceConnectionStatus.Ready, options?.maxTime ?? 20000);
|
||||||
const sub = new StreamDispatcher(conn, channel);
|
return conn;
|
||||||
this.cache.set(channel.guild.id, sub);
|
|
||||||
return sub;
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
conn.destroy();
|
conn.destroy();
|
||||||
throw err;
|
throw err;
|
||||||
|
|
Loading…
Reference in a new issue