Setup 3 bots with Sapphire

Hello ! I'd like to set up 3 bots with Sapphire. But I'd like to have everything in the same code to share certain components. What I'm doing for the moment is creating 3 instances of SapphireClient, in which I define a path to retrieve commands, listeners, etc ... My problem: I'd like to add access to my database in container but I can't see how to do it. Is it possible to define a property in container as soon as SapphireClient is initialised? Thanks! (this is my first experience with SapphireClient)
Solution:
you're far far better off making a module with its own package.json for the shared code and then use workspaces to install it in your bots
Jump to solution
13 Replies
KaydaFox
KaydaFox7mo ago
Sapphire Framework
Using and extending container | Sapphire
The container is a way in which Sapphire achieves Dependency Injection. This is a very useful feature, since it
Mathias
Mathias7mo ago
Oh, the container isn't specific to the SapphireClient, it's common to all the code?
KaydaFox
KaydaFox7mo ago
Yup The client is on the container Not the other way around I'm not sure how it handles multiple bots in the same codebase though
Favna
Favna7mo ago
that does mean that container.client will be the last constructed client tho so not a good idea
Solution
Favna
Favna7mo ago
you're far far better off making a module with its own package.json for the shared code and then use workspaces to install it in your bots
Favna
Favna7mo ago
src/
|- bot1/
|- package.json -> has @myproject/shared as dependency
|- bot2/
|- package.json -> has @myproject/shared as dependency
|- bot3/
|- package.json -> has @myproject/shared as dependency
|- shared/
|- package.json
package.json -> root package.json for workspace config
src/
|- bot1/
|- package.json -> has @myproject/shared as dependency
|- bot2/
|- package.json -> has @myproject/shared as dependency
|- bot3/
|- package.json -> has @myproject/shared as dependency
|- shared/
|- package.json
package.json -> root package.json for workspace config
Trust me when I say you'll ensure way way fewer headaches down the road that way. Not just with this particular connumdrem but many to come in the future
Mathias
Mathias7mo ago
I can't see how I can do it technically
Mathias
Mathias7mo ago
I see! But I think that's a pretty heavy structure for a personal bot
Favna
Favna7mo ago
it really is not it's just being smart
Mathias
Mathias7mo ago
Ok, and can I have a lib (for exemple discordjs), on top package.json ?
Favna
Favna7mo ago
yes but when using workspaces you'll only have 1 node_modules anyway as symlinks are used so there is no difference, RTM
Mathias
Mathias7mo ago
Ohh ok, thanks !