Different approach for commands order #10118
Replies: 3 comments
-
But then you'd have to add stuff to that index file every time you add a command, and you can absolutely do that for your project, but discord.js just went with you write the loading once and don't have to worry about importing, the new guide that's still in development just uses create-discord-bot, a CLI to generate boilerplate but it also does something similar. |
Beta Was this translation helpful? Give feedback.
-
Yes of course is a personal preference to not rely the functionality on file system modules loops but just maintaining the code tight together using indexes. Thanks a lot for replying ! |
Beta Was this translation helpful? Give feedback.
-
Also do note that while your code looks shorter for now it‘ll get longer the more commands you add. While the guide code stays the same, so with more commands the total line count would grow further in your solution. And if you loop over an fs result or hide the looping in an Object.values call doesn’t change that you still loop. |
Beta Was this translation helpful? Give feedback.
-
Hello everybody.
I was recently reading the https://discordjs.guide/ and the command organization system seemed a little "overcoded" for me. And i want to share an approach i tried and seem to work.
In the current guide the setup performs a search + evaluation for each file inside the /utility folder in which using fs and path modules with a loop we do this:
folder structure:
basically with this code we sync with the folder, evaluate extension ".js" , evaluate 'data' and 'execute' strings inside files, etc..
My idea is to organize the structure like this.
Then inside index.js
Then on deploy-command or anywhere else we can have all of our commands required by calling just index.js
e.g. inside deploy-command.js for registering commands.
and on the index.js
I hope you find this approach leaner and helpful. Im very brand new to this Discord.js module and appreciate all recommendations and tips.
Cheers!
Beta Was this translation helpful? Give feedback.
All reactions