首页 > 解决方案 > ytdl-core 出现“找不到模块”错误

问题描述

我正在开发一个 Discord 机器人,我正在使用ytdl-core, opusscriptand ffmpeg-binariesfromnode_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 和我的所有库,但仍然抛出相同的错误。我也尝试调试它制作一个新的机器人,但没有,问题仍然存在。

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,机器人不会执行任何操作并将该错误发送到控制台。

标签: javascriptdiscord.js

解决方案


推荐阅读