Problem with syntax from guide's command & event handlers

Wasn't sure if this fell under djs or other-js since its about the syntax used in the guide but not specifically djs library content. The command & event handlers use a different syntax for importing then what node has been allowing me to use. I tried changing it as I have been but it does not allow me/also does not work as it then tells me "An import declaration can only be used at the top level of a module." Images shown are for the command handler, but the event handler contains the same line/syntax.
10 Replies
d.js toolkit
d.js toolkit9mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Du
DuOP9mo ago
No description
Du
DuOP9mo ago
No description
Du
DuOP9mo ago
No description
monbrey
monbrey9mo ago
The guide samples are written in CommonJS If you're using import at the top of your files, you'd be writing ESM However you can't import that way in the middle of a file - you'd need to be using the dynamic import function https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import
Du
DuOP9mo ago
Oh, so its simply changing required() to import()? Thank you
monbrey
monbrey9mo ago
There's a couple more steps to it - this is an async function for example
Du
DuOP9mo ago
I think I understand, this seems to work though I think much of what else I've done following the guide doesn't completely work since I'm not using CommonJS
No description
monbrey
monbrey9mo ago
uhhh no you dont make it an async function that you dont call you await it
Du
DuOP9mo ago
So just "await" instead of "async () =>" ? Sorry, I am still rather new to JS. I should probably go rewatch/reread the asyncronous guides as I think I must not have fully understood it.
Want results from more Discord servers?
Add your server