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:Jump to 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
13 Replies
They have a guide on how add things to the container here https://www.sapphirejs.dev/docs/Guide/additional-information/using-and-extending-container
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
Oh, the container isn't specific to the SapphireClient, it's common to all the code?
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
that does mean that
container.client
will be the last constructed client tho so not a good ideaSolution
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
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
I can't see how I can do it technically
workspaces | npm Docs
Working with workspaces
I see!
But I think that's a pretty heavy structure for a personal bot
it really is not
it's just being smart
Ok, and can I have a lib (for exemple discordjs), on top package.json ?
yes but when using workspaces you'll only have 1 node_modules anyway as symlinks are used so there is no difference, RTM
Ohh ok, thanks !