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
}