当我尝试在Discord中播放音乐时,出现以下错误:
我应该如何修理?
const args = message.content.substring(PREFIX.length).split(" ");
const searchString = args.slice(1).join(" ");
const url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : " ";
const serverQueue = queue.get(message.guild.id);
在这里开始播放音乐。我尝试了StackOverflow的其他功能,但没有成功。我想知道在什么地方以及什么地方进行更改才能使其正常工作。
if (message.content.startsWith(`${PREFIX}play`)) {
const voiceChannel = message.member.voice.channel;
if (!voiceChannel) return message.channel.send("intra intr-un canal puiu meu");
const permissions = voiceChannel.permissionsFor(message.client.user);
if (!permissions.has("CONNECT")) return message.channel.send("nu merge maica sa intru acolo");
if (!permissions.has("SPEAK")) return message.channel.send("nu merge maica sa vorbesc. da-mi permisiune");
try {
var video = await youtube.getVideoByID(url);
} catch (error) {
console.log(error);
try {
var videos = await youtube.searchVideos(searchString, 1);
var video = await youtube.getVideo(videos[0].id);
} catch (error) {
console.log(`am avut o eroare: ${error}`);
return message.channel.send("n-am gasit cd-u bosule");
}
}
if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) {
const playlist = await youtube.getPlaylist(url).catch((erro) => {
return message.reply("A Playlist é privada ou não existe!");
});
const videos = await playlist.getVideos().catch((erro) => {
message.reply("Ocorreu um problema ao colocar um dos vídeos da playlist na fila!'");
});
for (const video of Object.values(videos)) {
try {
const video2 = await youtube.getVideoByID(video.id);
await handleVideo(video2, message, voiceChannel, true);
} catch {}
}
message.reply(`A playlist **${playlist.title}** foi adicionada a lista de músicas!`);
}
const songInfo = await ytdl.getInfo(args[1]);
const song = {
id: video.id,
title: video.title,
url: `https://www.youtube.com/watch?v=${video.id}`,
};
if (!serverQueue) {
const queueConstruct = {
textChannel: message.channel,
voiceChannel: voiceChannel,
connection: null,
songs: [],
volume: 5,
playing: true,
};
queue.set(message.guild.id, queueConstruct);
queueConstruct.songs.push(song);
try {
var connection = await voiceChannel.join();
queueConstruct.connection = connection;
play(message.guild, queueConstruct.songs[0]);
} catch (error) {
console.log(`am avut o eroare: ${error}`);
queue.delete(message.guild.id);
return message.channel.send(`am avut o eroare bosulica, mai baga o fisa: ${error}`);
}
} else {
serverQueue.songs.push(song);
return message.channel.send(`**${song.title}** s-a bagat in pleilist`);
}
return undefined;
}
请注意,我已经安装了simple-youtube-api
,ytdl-core
和opusscript
。
我应该安装其他东西吗?