Answer the question
In order to leave comments, you need to log in
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"
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question