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

132
Vistas
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 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