javascript - ytdl-core 出现“找不到模块”错误
问题描述
我正在开发一个 Discord 机器人,我正在使用ytdl-core
, opusscript
and ffmpeg-binaries
fromnode_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,机器人不会执行任何操作并将该错误发送到控制台。
解决方案
推荐阅读
- python - 在 Python 中递归地将 DOS 文件转换为 UNIX 格式
- mysql - mysql 服务作为类型:ExternalName 无法从 Kubernetes ( minikube ) 中的其他命名空间连接
- android-studio - Android Studio - IntelliJ 新 java 类向导
- python - 找到宽度范围和窗口积分之间的最高峰
- php - PHP:允许类仅在另一个类中实例化的方法
- azure - 如何在 Azure 中创建自定义角色,以便其他用户只能查看 blob 容器中的文件列表,但不能查看其内容(RBAC)
- dialogflow-es - 如何实现过滤器提取范围自定义实体
- c++ - 为什么我的输出与输入不同?(C++)
- reactjs - 如何更改默认的“材料表”图标
- groovy - 如何从同一级别的json文件中查找和获取值?