我希望我可以从json文件夹中编译/放置以下项目。
const Discord = require ('discord.js');
const client = new Discord.Client();
const {prefix, token,} = require('./config.json');
const fs = require ('fs');
client.login(token)
client.on('message', message => {
if(message.content.startsWith(prefix + "TC")) { //TC = team create
var args = message.content.split(' ').join(' ').slice(4);
if(!args) return message.channel.send("No")
var TeamCreate = `{"NameTeam": "${args}", "ManagerTeam": ${message.author.id}}`
fs.writeFile("./team.json", TeamCreate, (x) => {
if (x) console.error(x)
})}});
The json file will display :
{"NameTeam": "teste","ManagerTeam": 481117441955463169}
而且我希望每次下订单时,json代码都不会删除而是添加。
例子: 1个第一订单= {“ NameTeam”:“ teste”,“ ManagerTeam”:481117441955463169} 2次订单= {“ NameTeam”:“ teste”,“ ManagerTeam”:481117441955463169},{“ NameTeam”:“ teste2”,“ ManagerTeam”:1234567890}
先感谢您
From what I understand, you want to make a
json
file that contains a list of teams.The easy way to do that is to read and parse the json, make changes to it, and then stringify the jsonand update the file. Also, making json with strings is really messy and can lead to syntax errors, while in javascript turning js objects into json is as simple as doing
JSON.stringify(javascriptObject)
尝试这样的事情:
希望这会有所帮助,并祝你好运。