Update play.js and queueManager.js

This commit is contained in:
Wizzard 2024-08-17 19:30:48 -04:00
parent 5fd238ea79
commit 39d1d71f44
2 changed files with 22 additions and 3 deletions

View File

@ -173,6 +173,12 @@ module.exports = {
}
const info = JSON.parse(stdout);
if (!info.entries || info.entries.length === 0) {
message.reply('No results found for your search.');
return;
}
const url = info.entries[0].webpage_url;
title = info.entries[0].title;
@ -223,4 +229,4 @@ function isValidURL(string) {
} catch (_) {
return false;
}
}
}

View File

@ -1,4 +1,4 @@
const { createAudioPlayer, createAudioResource, AudioPlayerStatus, joinVoiceChannel } = require('@discordjs/voice');
const { createAudioPlayer, createAudioResource, AudioPlayerStatus, joinVoiceChannel, VoiceConnectionStatus } = require('@discordjs/voice');
const fs = require('fs');
const queueMap = new Map();
@ -88,12 +88,25 @@ function playNextInQueue(guildId) {
}
function playTrack(guildId, voiceChannel, track) {
const connection = joinVoiceChannel({
let connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: guildId,
adapterCreator: voiceChannel.guild.voiceAdapterCreator,
});
connection.on(VoiceConnectionStatus.Disconnected, async (oldState, newState) => {
try {
await Promise.race([
entersState(connection, VoiceConnectionStatus.Signalling, 5_000),
entersState(connection, VoiceConnectionStatus.Connecting, 5_000),
]);
} catch (error) {
connection.destroy();
currentTrackMap.delete(guildId);
queueMap.delete(guildId);
}
});
const audioPlayer = playerMap.get(guildId) || createAudioPlayer();
playerMap.set(guildId, audioPlayer);