Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

252
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda