Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

253
Vistas
Trying to use replace() method on files by passing the string not working - JS

I'm trying to replace a string, but when i try to do it on a file, it does not work. Or only the last file will work.

Main Code (inside a class method):

const funcs = fs.readdirSync(path.join(__dirname, "../funcs")).filter(file => file.endsWith('.js'));
        
this.functions = this.code.split("$");

const functions = this.functions

for (const func of funcs) {
    for (let x = functions.length - 1; x > 0; x--) {
         let i = 0;
         const res = await require(`../funcs/${func}`)(client, this.code.toString(), this._author);

         console.log(x);
         console.log(res);
         console.log(functions);

         return res;
         i++;
    }
}

ping.js:

const ping = (client, code, author) => {
    const result = code.split("$[ping]").join(client.ws.ping)

   return result;
}

module.exports = ping;

messageAuthorTag.js:

const Util = require('../utils/util');

const messageAuthorTag = (client, code, author) => {
    if (code === null) return;
    
    const res = code.split("$[message.author.tag]").join(`${author.tag}`);

    return res;
}

module.exports = messageAuthorTag;

Using it : "ping: $[ping] author tag: $[message.author.tag]"

Output: ping: $[ping] author tag: Example#0001

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your issue is that you return res in the middle of a for loop. This means it won't do anything else in the function and will skip the rest of the loops (like running the other functions!)

As an additional note, you could also remove the let i = 0 and i++ since that doesn't seem to be used for anything.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda