What's the preferred way of accessing collections in a command file?
Currently I have something like this
Where I just send the collections along when I execute the command from the main file, depending on the command but this feels a bit hacky, as does having a separate file exporting collections. What should I be doing? Thanks!
npm list discord.js: 14.14.1
node -v: v21.1.0
11 Replies
- 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!
- ✅
Marked as resolved by OPget your collection within the command module?
Yeah, if like if I was following the guide for making a currency system, except I wanted my commands to broken down into individual files. How would I access the collections defined to modify them from within that command file. Or is that not what you're asking?
I suppose I could also define it on the client object like the commands collection but I'm not sure what the right hing to do here is.
How is your collection defined
just
in the main file where that try catch block from the top is
So it doesn’t persist between restarts, is that not what you want for a currency statement
System **
I have an sqlite database for that
I see, I mean the better approach would be to always pass uniform arguments to your interactions instead of hard coding the same function but executing different arguments
In this case attaching it to client would be best or you b can get access to the collection (or the date of the database) within your indiv command handling
Okay, thanks! I'll attach it to the client, that makes sense to me. Would accessing the collection within the command handling just be an import statement, or?
interaction.client.currency
right, that's if i attach it to the client, I meant when you said "or you b can get access to the collection (or the date of the database) within your indiv command handling". Sorry for the confusion