我将在下面列出命令逻辑本身以及所有已安装的依赖项。基本上,到目前为止,只要我在Discord中使用我提供的任何youtube链接运行该命令,该机器人便会加入并且一切正常运行,但是不久之后,该机器人在VSC中出现错误,错误为“视频不可用”。我浏览了各种论坛并观看了很多视频,但根本找不到任何解决方案。
播放命令逻辑:
if (musicArgs.startsWith('play')) {
let musicPlayPrefix = 'play';
let musicPlayArgs = musicArgs.slice(musicPlayPrefix.length).trim();
if (message.member.voice.channel) {
const connection = await message.member.voice.channel.join();
const dispatcher = connection.play(await ytdl(musicPlayArgs), { type: 'opus'})
dispatcher.on('error', console.error);
dispatcher.on('start', () => {
message.channel.send(`**Now Playing:** *${musicPlayArgs}`);
});
dispatcher.on('finish', () => {
message.channel.send(`**Music Finished!**`);
});
}
else {
message.channel.send(`You're not in a voice channel! Retry the command inside of one.`);
}
}
Package.json中的依赖项:
"dependencies": {
"@discordjs/opus": "github:discordjs/opus",
"discord.js": "^12.3.1",
"ffmpeg-static": "^4.2.7",
"hypixel-api-reborn": "^2.2.4",
"libsodium-wrappers": "^0.7.8",
"ytdl-core-discord": "git+https://github.com/amishshah/ytdl-core-discord.git"
}