Share sapphire stuff with multiple bots & possible monorepo setup
The question is what the better way to share sapphire stuff like utilities, handlers, commands folders with multiple bots? I need to have different bots for each category for example: economy, moderation, tickets, events, bots. Right now my project structure looks like this:
I have utilities under lib folder, and I have some shared typings in it too. Using workspace I have this "package" in my bots. Also I got
node_modules
at this folder and all bots is using the same packages from it.
Also because of that I wanna ask how exactly sapphire works. Will it be the problem that all bots will use the same node_modules
? Because as I understood from container
thing you do your magic under the hood in package folder. So it might be a problem when different bots will try to use the same package.
Each bot is independent project with their tsconfig, etc.. and they only share same node_modules
from root folder as I said before.
Will appreciate any tips/links to topics about better structure to implement, first time doing something like that8 Replies
you just give the subpackages their own package.json and import/require them just like any other library and it will just work. Nothing special needed. As long as every bot is its own instance of Sapphire they dont have anything conflicting like container. Container is attached to a client instance and every bot starts its own instance.
So I added to the common package that I want to share between my bots 1 utility class. Right now all what I just need to do is register path via
stores
for that folder and thats it? This is how structure of bot looks like right nowIf you want your shared stuff to register whole pieces then you should write them as Sapphire plugins, see the sapphiredev/plugins repository for examples.
I don't want shared stuff to register pieces. I want to SHARE those pieces. I want all bots to
registerPath
for utilities from those folder sapphire-utilities
i'll not use them in this common package. I tried to register them like this:
But this didnt work. I even tried to register basic utilities that are in bot's root folder with others stores like command, listeners etc. and they didn't register even.
I have needed plugin for utilities to work, I think I installed literally everything. Also registering plugin in my _setup.ts
file.
And I have another question about container
from @sapphire/pieces
idk why but I can't import it from that library. TS giving me error like this library didn't exist. And when I tried to install it manually I can't see useful stuff like logger
, tasks
, utilities
... Only props that I declare in global.d.ts
(augment)
Also was playing around your answer, my types that I share and other stuff works fine. Tried to launch multiple bots at the same time using same node_modules
and everything was fine too. Right now only 1 struggle is to find a way to share utilities that I will need in each bot. Maybe I have a problem with bot configuration, idk..You should (read: must) make the shared stuff register the pieces. For example, look at plugin-api: https://github.com/sapphiredev/plugins/tree/main/packages/api/src
GitHub
plugins/packages/api/src at main ยท sapphiredev/plugins
Plugins for the Sapphire Framework. Contribute to sapphiredev/plugins development by creating an account on GitHub.
utilities
prop from related utilities plugin to container from @sapphire/pieces
? Should I somehow add typings to d.ts
file?
Checked docs again, and I see that all what you need to do is just add typings in d.ts file to @sapphire/pieces
module and custom props should be accessible by container from framework folder. Idk why it's not adding types. Maybe the problem is that I have d.ts file named global
not augment
:NotLikeThis:@sapphire/pieces
as dependency, deleted node_modules and reinstalled everything. Now container from pieces folder has utilities, tasks etc ๐๐ฟ
Figured out why utilities wasn't working... You can access them only after bot logins :Maaaan: Seems like I'm very bad at reading docs.
Tried implementing example above but nothing workout for me (probably because I can't understand how to implement it correctly) so I moved back to my initial thoughts to just registerPath
for folder with utilities from my package in node_modules and this way I had a success. I probably will stick around with that solution but I think my overall implementation for shared package is garbage :D But I can't figure out how to make it correct. So if it works for now I won't touch it. I wish I could get someone to just show me how to do it the right way :Maaaan:
I think I can upload my project to git and show how I implemented everything (project size is small, just implemented basic structure for future) but I think you have your own stuff to do. So do I just close this post or mark your message as solution?yeah... besides if it works for you that's fine too. That's the most important part.
Then I'll close this one. Thanks for help ๐๐ฟ