title: how add data to json files with discord js
body: <p>Hi I try to make sure that as soon as my discord bot joins a server it writes the es of the server in the JSON file and then the first channel of the discord server below but it does not work.</p>
  <pre><code>client.on(&quot;guildCreate&quot;, (guild) =&gt; { // This event triggers when the bot joins a guild. 
      let rawdata = fs.readFileSync('guilds.json');
      let guilds = JSON.parse(rawdata);
      console.log(`Joined new guild: ${guild.name}`);
      var chx = guild.channels.cache.filter(chx =&gt; chx.type === &quot;text&quot;).find(x =&gt; x.position === 0);
      client.newGuild [chx.guild.id] = {
          MemberAdd: chx.id,
          MemberRemove: chx.id
      }
      fs.writeFile(&quot;./guilds.json&quot;, JSON.stringify (client.newGuild, null, 4), err =&gt; {
          if (err) throw err;
          console.log('Server succefull add')
      })
  });
  </code></pre>
  <p>I get this error
  <a href="https://i.stack.imgur.com/L2HDh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/L2HDh.png" alt="enter image description here" /></a></p>
  <p>I try to do this:</p>
  <pre><code>{
      &quot;801502579829112852&quot;:{
         &quot;MemberAdd&quot;:&quot;801514313340289034&quot;,
         &quot;MemberRemove&quot;:&quot;802125586923257886&quot;
      },
      &quot;802163006698946570&quot;:{
         &quot;MemberAdd&quot;:&quot;802163007173951521&quot;,
         &quot;MemberRemove&quot;:&quot;802163007173951521&quot;
      }
   }
  </code></pre>
  <p>Thank you for your help !</p>