-1

pre-script: I'm a very noob at javascript and I'm using my c# knoledge to create a Discord bot in javascript, so I'm sorry if this question is too dumb.

I have a code to write down in a json file an array called tarefas using this code:

tarefas.push(subcomando);

bot.tarefasFile ['wait tasks'] = {
    task : tarefas
}
fs.writeFile('./tarefas.json', JSON.stringify(bot.tarefasFile,null,4),
err => {
    if (err) throw err;
});
cmd.channel.send('`' + subcomando + '` added to tasks.');

(subcomando is the message when someone sends w_add task_[subcomando] in my Discord server. Example below)

The output json file tarefas.json is:

{
"wait tasks": {
    "tasks": []
}

For now, my code resets the value of the array tarefas when the bot restarts, so I want to reload its values from the tarefas.json file, precisely from the "tasks": [] array. How do I do that?

extra: Example from when the json file is populated with some "tasks":

screenshot of my discord

{
    "wait tasks": {
        "tasks": [
            "hi",
            "hello",
            "bye",
            "math exam tomorrow"
        ]
    }
}
Klausbdl
  • 1
  • 2

1 Answers1

0

Fixes by using txt file instead of json file. write: https://www.geeksforgeeks.org/javascript-program-to-write-data-in-a-text-file/ read: Reading local text file into a JavaScript array fix the split function not working: What is causing the error `string.split is not a function`?

Klausbdl
  • 1
  • 2