Update play.js and queueManager.js
This commit is contained in:
parent
5fd238ea79
commit
39d1d71f44
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue