A
A
Artem Melnykov2020-02-10 11:10:51
JavaScript
Artem Melnykov, 2020-02-10 11:10:51

Why is the file being written to?

I write this code:

const Discord = require("discord.js");
const fs = require("fs");
const profile = require("../database.json")
let embed;
const fetch = require("node-fetch")

module.exports.run = async (bot, message, args) => {
  if (!args[0]) return message.reply('Ты не ввёл имя игрока!');
  let Nick = args[0];
  let url = `https://api.vimeworld.ru/user/name/${Nick}`;
let response = await fetch(url);

let data = await response.json();
  if(!data){ return message.reply(`Игрок "${Nick}" не найден `);}
    for(var i = 0; i < data.length; i++) {
      console.log(data[i])
      if(!profile[data[i].id]) {
      profile[data[i].id] = {
          username: data[i].username,
          lvl: data[i].level,
          likes: 0,
          dislikes: 0,
          rank: data[i].rank
      };

      fs.writeFile('../database.json', JSON.stringify(profile), function(error){
          if(error) throw error;
      }
    };
  };

  message.channel.send(`${Nick} был добавлен в базу`)
};

module.exports.help = {
  name: "new"
}

However, nothing is written and there are no errors

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question