【发布时间】:2021-06-30 20:01:47
【问题描述】:
我正在尝试制作一个命令命令,允许作者为其服务器设置命令, 这是为了更新一个 json 文件而不是覆盖它, 我正在使用 node.js 和 discord.js
const fs = require('fs')
module.exports = {
name: 'setsuggest',
execute(client, message, args, discord, cmd){
const channelid = args[0]
const serverid = message.guild.id
fs.readFile('suggest.json', function (err, JsonData) {
var json = JSON.parse(JsonData)
let data = {
[serverid]: channelid
};
json.push(data)
fs.writeFile('suggest.json', JSON.stringify(json), function (err) {
if (err) throw err;
console.log('Updated')
})
})
}
}
我做错了什么?
【问题讨论】:
-
我怀疑 json 是一个对象而不是一个数组。 stackoverflow.com/questions/8925820/…
标签: javascript node.js discord.js