Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tutorial ES6 update #1554

Open
time4nothing opened this issue Mar 12, 2024 · 3 comments
Open

tutorial ES6 update #1554

time4nothing opened this issue Mar 12, 2024 · 3 comments
Labels
t: request Suggestion to add new or change existing content

Comments

@time4nothing
Copy link

Is your feature request related to a problem? Please describe.

Your current tutorial is filled with require() and module.exports. Converting to the ES6 import/export does not work.

  1. your dynamic command file setup has a require() that I could not figure out how to replace (admittedly, still learning node, but getting fairly proficient at it)
  2. get error "SlashCommandBuilder is not a constructor" trying to convert command module

Describe the solution you'd like

I would like to see an updated tutorial with proper ES6 import/export so I can properly learn current coding methods.

Describe alternatives you've considered

No response

Additional notes

I do not wish to learn outdated coding methods, so converting my project to CommonJS is a last resort that I would prefer not to do.

@time4nothing time4nothing added the t: request Suggestion to add new or change existing content label Mar 12, 2024
@monbrey
Copy link
Member

monbrey commented Mar 12, 2024

Thanks for the feedback - we do have plans to rewrite the examples to ES6. In fact, many already have been but the updated guide has not yet gone live.

For information on how to use ES6 import correctly, check out https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import

For example, importing SlashCommandBuilder is import { SlashCommandBuilder } from 'discord.js';

The equivalent to the in-line require() you mentioned is the dynamic import: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import

@time4nothing
Copy link
Author

Thank you for the response. I am looking forward to that update, as every other tutorial I could find also used the require() syntax, despite saying it's updated for ES6...

In regards to your helpful advice and links:

1: I did import the SlashCommandBuilder in that way, but running the code gives me an error that SlashCommandBuilder is not a constructor. Worked fine if I c/p the lines directly into my index.js though.

2: I did try the import() function, but trying to use the object that should have been imported, was not working for me. Probably something I am doing wrong, but so far unable to work it out.

@Prashantjha14
Copy link

Along with ES6, it will be great if you add TypeScript examples :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t: request Suggestion to add new or change existing content
Projects
None yet
Development

No branches or pull requests

3 participants