Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140705

How do I append data to a JSON File (Involves: Discord.js, JSON)

$
0
0

I have a JSON File: (invitelist.json)

{
}

Every time the "guildMemberAdd" event gets fired off, an invite is created:

bot.channels.get('642609367195189268').createInvite({
  temporary: false,
  maxAge: 0,
  maxUses: 0,
  unique: true
},`This is ${member}'s invite link.`).then(invite => {
  bot.channels.get('642609367195189268').send(invite.code);
});

How do I append to the JSON File?:

{
  "invite": {
    "code": "",
    "timecreated": "",
    "author": ""
  }
}

When a new invite is created, it'll add another invite object:

{
  "invite-1": {
    "code": "",
    "timecreated": "",
    "author": ""
  },
  "invite-2": {
    "code": "",
    "timecreated": "",
    "author": ""
  }
}

The address to the invitelist.json is simply invitelist.json. Can you please give me some code that will make it work properly? also an explanation on how it works would be awesome! If you need more information please just kindly ask in the comments below :D

I have looked around, there's no questions on stackoverflow that answers this. Please don't mark it as duplicate. (or at least send a link to the other doppelgänger in the comments).


Viewing all articles
Browse latest Browse all 140705

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>