【发布时间】:2021-11-08 17:17:54
【问题描述】:
const fs = require('fs');
const fileName = './prices.json';
const file = require(fileName);
const price = require('./prices.json');
const fileName = './prices.json';
if(tmd = message.match(/^!change max (\D+)/)) {
if(steamID == config.ownerID){
var kak = tmd[1];
var sellu = 0;
sellp = parseInt(message.replace("!change max "+kak,''));
selli = message.replace("!change max ",'')
selli = selli.replace(" "+sellp,'')
if (file[selli].max !== undefined){
file[selli].max = sellp;
fs.writeFile(fileName, JSON.stringify(file), function writeJSON(err) {
if (err) return console.log(err);
client.chatMessage(steamID,"Succesfully changed max of " + selli)
});
}else{
client.chatMessage(steamID,"There was an problem in changing, you might put wrongly name remember about capital letters or\n just do !list and ctrl+c ctrl+v")
}
}
}
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'max' of undefined
由于某种原因不想在它不受保护时跳过错误
【问题讨论】:
标签: javascript node.js if-statement error-handling undefined