Mixing commonJS and ES6
Is there any point in me using es6 and mixing it with discordJS? Meaning I will use
import
and require
.
Is discordjs ES6 compatible with regards to using import?
Currently I have discordjs files saved as .cjs
files11 Replies
why use both? just stick to one, djs supports both
How do I replace this require in ES6?
unless importing conditionally is a thing now?
await import()
ah
how about for commands?
Not sure if ES6 lets me do inline functions like this?
has to be a named function, will discordjs be fine with this?
MDN Web Docs
export - JavaScript | MDN
The export declaration is used to export values from a JavaScript module. Exported values can then be imported into other programs with the import declaration or dynamic import. The value of an imported binding is subject to change in the module that exports it — when a module updates the value of a binding that it exports, the update will be ...
that's not something on djs side though
djs doesn't have any command execution logic, that's up to you
your actual question should be "will my code be fine with this?"
and that depends, I'm not sure how your entire code looks like
yeah good point, I just followed the tutorial on the discordjs website
but my guess is when we
require
the command file, it default exports that function, so I guess I could just define a function and export default newFn
are you new to js or something?
for named export use
export {hello1, hello2}
for default exports, use export default hello1
and, use it as:
import {hello1, hello2} from "./module"
or, import defaultExportedFunction from "./module"
or, import defaultExportedFunction, {hello1, hello2} from "./module"
The issue has been marked as solved by support staff