Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
Discord.js escribe datos en el archivo

Oye, necesito ayuda aquí. Quiero estructurar un archivo JSON. Aquí abajo puedo explicarlo un poco mejor:

Tengo un channelId y un serverName y quiero guardarlos en un archivo de configuración con fs. Así es como se vería ahora:

 { "server": "MyServer" }

Pero quiero que se vea así:

 [ { "channelId": "MyChannel", "info": [ { "server": "MyServer" } ] } ]

Aquí está mi código:

 const server = "MyServer" const channel = "MyChannel" //I want this to be at the top const template = { //this must be edited i think server: "Cool Server", } template.server = server; fs.writeFileSync("channels.json", JSON.stringify(template, null, 2));

Con "servidor" me refiero al servidor donde existe el canal. Gracias por ayudarme ;-)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Hay muchas maneras de hacer esto. Pruebe esto como una solución fácil.

 const server = "MyServer"; const channel = "MyChannel"; //You want this to be at the top const template = [ { channelId: "Your Channel", info: [ { server: "Your Server", }, ], }, ]; template[0].channelId = channel; template[0].info[0].server = server; fs.writeFileSync("channels.json", JSON.stringify(template, null, 2));

Más adelante, puede usar una función de map o bucle for en la matriz de plantillas para agregar canales y servidores dinámicamente.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!