我将在下面列出命令逻辑本身和所有已安装的依赖项。基本上,每当我在 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"
}