javascript - “TypeError:无法读取未定义的属性‘名称’”在 vscode
问题描述
D:\GG\PanCakeBot\index.js:18
bot.commands.set(props.help.name, props)
^
TypeError: Cannot read property 'name' of undefined
at D:\GG\PanCakeBot\index.js:18:41
at Array.forEach (<anonymous>)
at D:\GG\PanCakeBot\index.js:16:16
at FSReqCallback.oncomplete (fs.js:171:23)
^ 当我尝试在 vscode 中使用此命令运行不和谐机器人时,这是一个错误。
fs.readdir('./commands', (err, files) => {
if(err) return console.log(err);
let jsfile = files.filter(f => f.split(".").pop() == 'js');
if(jsfile.length == 0) {return console.log("Could not find any commands!")}
jsfile.forEach(f => {
let props = require(./commands/${f});
bot.commands.set(props.help.name, props)
})
我在那里错过了什么以及如何解决它?
解决方案
props.help
未定义,因此读取props.help.name
会导致错误。console.log()
你,,,看看jsflile
有什么问题f
。props
推荐阅读
- php - 如何将带有翻译的记录添加到夹具 symfony
- flutter - Flutter:如何模块化底部导航栏
- vue.js - 输入字段值不断重置@input?
- django - 从带有 400 错误请求的 ajax 错误将数据发布到 DjangoRestFramework api
- c# - 在数据库中移动磁贴/文本框存储位置
- linux - 在 /usr/bin 中创建自定义命令不起作用
- python - 如何为 Django Tables2 使用 Django __str__() 方法
- matlab - MATLAB 中的 3D 海洋温度插值
- node.js - 将 NodeJS 和 NPM 更新到下一个版本?
- node.js - 如何格式化 JSON 字符串并包含图片?