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

133
Visualizações
Function not returning to another file

so I have a problem. I have two files, testMode.js and initialize.js, testMode.js requires initialize.js and runs the initialize functions, all works well until there's time to return back to testMode.js. In initialize.js, all works perfectly, when I print the user variable, it prints, but when I try returning the same variable, it is suddenly undefined in testMode.js.

Here is my code: testMode.js

// # MODULES #
const initModule = require('./initialize.js');

// # VALUES #
const botCmdChannel = process.env.BOT_COMMANDS_CHANNEL;

function error(issue) {
    console.log('An error has occured in test mode. Exiting with exit code 1. Error:' + issue);
    process.exit(1);
}


async function test(bot) {
    bot.login(process.env.TOKEN);
    bot.on('ready', async () => {
        console.log('Logged in successfully in test mode.');
        console.log('Attempting to initialize in test mode');
        const channelObj = bot.channels.cache.get(botCmdChannel);
        const message = await channelObj.send('Došlo k aktualizaci bota, probíhá test funkcí.');

        initModule.initialize(message, bot).then(function(response) {

            console.log(response);

            if (!response) {
                error(' Initialization failed.');
            } else {
                console.log('Initialization successful');
                process.exit(0);
            }

        });

        bot.on('error', issue => {
            error(issue);
        });
    });
    }


exports.testmode = test;

And the part of initialize.js that is not working:

       edupage.login(process.env.USER, decryptedpass, {
            edupage: process.env.SCHOOL
        }).then(user => {
            console.log('-----PŘIHLÁŠENÍ OK-----');
            sentembed3.delete();
            origmsg.channel.send({
                embeds: [embed4]
            });
            console.log('-----KONEC INICIALIZACE------');
            isInitialized = true;
            edupageuser = user;
            console.log(user) //works
            return user; //doesnt work
        }

about 4 years ago · Juan Pablo Isaza
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