我正在开发Discord机器人,并使用ytdl-core
中的opusscript
,ffmpeg-binaries
和node_module
来完成。该机器人运行良好,但是当我使用命令播放音乐时,它却无能为力:它唯一要做的就是连接到语音通道并在控制台中引发错误。错误提示:
Error: Cannot find module 'ytdl-core'
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at voiceChannel.join.then (/app/index.js:365:36)
at -anonymous-
at process._tickCallback (internal/process/next_tick.js:189:7) code:
'MODULE_NOT_FOUND'
我尝试从项目中重新安装npm和所有库,但仍然抛出相同的错误。我还尝试调试它以制造一个新的bot,但没有任何问题,问题仍然存在。
case "play":
let voice - Chan = message.member.voiceChannel;
let songURL = args.slice(1).join(' ');
if (!voiceChan || voiceChan.type !== 'voice') {
message.channel.send('¡You need to join in a Voice Channel First!!.');
} else if (message.guild.voiceConnection) {
message.channel.send('I\'m already in a Voice Channel!.');
} else {
message.channel.send('Connecting...').then(m => {
voiceChan.join().then(() => {
m.edit('Connected!.').catch(error => console.log(error));
const ytdl = require('ytdl-core');
let voiceChan = message.member.voiceChannel;
if (!voiceChan) return message.channel.send('You need to join a voice channel!!.');
if (!songURL) return message.channel.send('Input a Youtube URL .');
voiceChan.join()
.then(connection => {
const url = ytdl(songURL.join(' '), {
filter: 'audioonly'
});
const dispatcher = connection.playStream(url);
//events:
dispatcher.on('end', () => {});
dispatcher.on('error', e => {
console.log(e);
});
//functions:
dispatcher.setVolume(0.5);
dispatcher.time;
dispatcher.end();
message.delete();
message.channel.send('now playing!: ' + songURL);
}).catch(console.error);
}).catch(error => console.log(error));
}).catch(error => console.log(error));
};
break;
设置URL后,一切工作正常:如果发送URL,则漫游器不会执行任何操作并将该错误发送到控制台。