我有一个名为point.json
的JSON文件,它包含以下内容:
{
"name":{
"points":1
},
"anothername":{
"points":2
}
}
我在Discord.JS中输入命令后尝试列出它的内容,如:
name: 1
anothername: 2
,我尝试过类似的事情:
if(cmd === `${prefix}showwall`){
let target = ??;
let points= fs.readFile("points.json");
let uWarns = points[target].points;
message.reply(`${uWarns}`);
}
是否可以使这项工作?
答案 0 :(得分:0)
'use strict'
const points = require('./path/to/points.json')
message.reply(Object.keys(points).reduce((report, username) => {
report += `${username}: ${points[username].points}\n`
return report
}, ''))