#how do i import main.js/index.js file into a command.js file
13 messages · Page 1 of 1 (latest)
Why would you want to? Sounds like you want circular imports, which is never a good idea
No i dont want circular import
i mean like would
let module = require(`./main.js`)
client.on(Events.MessageCreate, (message) => {
if (!message.content.startsWith(prf) || message.author.bot) return;
const args = message.content.slice(prf.length).split(" ");
const command = args.shift().toLowerCase();
if (command === "ping") {
message.channel.send("Pong!");
}
});
import { prf } from "module";
import { client } from "module";
``` work?
Again, why would you want to? The client already is available as message.client
Your code shows you actually making circular imports
oh i did not know
i mean like i wouldnt want my src folder to be very empty
That’s even worse reason to do that
why?
i mean why is circular import bad?
Look at it this way: for A to work you need to first import B, so let‘s do that. While trying to import B we see we need to first import A, so let‘s do that.
(If node was dumb this would now recurse infinitely, thankfully node is a little more intelligent so it now throws and tells you it couldn’t load B fully because it tried to load a file that was about to be loaded but didn’t fully load yet)
how do i import A?
sorry for alot of questions it just that im having a struggling time to figure out discord.js/node.js