#there no easy way for me to ask this
1 messages · Page 1 of 1 (latest)
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
So the first file runs the second, and the second needs to run a bit from a third file, correct?
I think thats about right. if you want to see it in dms I can show so its easier to explain
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
how can I tell the second file to run all the code in the first one?
not first one
mb
third one
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
},
};
Alright, let me know how it goes!
Yeah that worked like it was supposed to. thank you!