#there no easy way for me to ask this

1 messages · Page 1 of 1 (latest)

torpid lantern
#

Alright what exactly are you trying to execute in a separate file?

distant latch
#

I have a long line of code that does various things like creating embeds and so on.

but I want the second file to grab the third file
and run the code from it

torpid lantern
#

So the first file runs the second, and the second needs to run a bit from a third file, correct?

distant latch
#

I think thats about right. if you want to see it in dms I can show so its easier to explain

torpid lantern
#

Nah I think I get the idea

#

We can use module.exports for this

#

In the third file, at the top, put:

module.exports = {
    async execute(incomingVariable) {
        //nothing yet
    },
};
#

whoops indents were lost lol

distant latch
#

how can I tell the second file to run all the code in the first one?

#

not first one

#

mb

#

third one

torpid lantern
#

To make the second one run the third, you require the third file like so:

const thirdFile = require('relative/path/to/third/file');

Then you execute it, passing whatever variables you need through:

thirdFile.execute(outgoingVariable);
#

in the third file however, you need to put all the code inside the braces where it currently says //nothing yet

#

For example

//second file
const thirdFile = require('thirdFile.js');
execute thirdfile(variable);
//third file
module.exports = {
  execute(variable) {
    //the code in the third file here
  },
};
distant latch
#

Thank you

#

ile give this a try

torpid lantern
#

Alright, let me know how it goes!

distant latch
#

Yeah that worked like it was supposed to. thank you!