How can I delay the loading of pieces?

Is there a way I can control when the pieces are loaded instead of having them loaded automatically on <SapphireClient>.login? I'd like to login to the client, then wait for the resolving of an async function, and then load the pieces in.
Solution:
mark them as internal by prefixing the file name with _ or putting them in a directory that doesn't get automatically detected by Sapphire (i.e. a folder other than arguments, commands, etc) then use ```ts import { container } from '@sapphire/framework'; container.stores.loadPiece({ name: 'name of the piece here',...
Jump to solution
7 Replies
Solution
Favna
Favna•2mo ago
mark them as internal by prefixing the file name with _ or putting them in a directory that doesn't get automatically detected by Sapphire (i.e. a folder other than arguments, commands, etc) then use
import { container } from '@sapphire/framework';
container.stores.loadPiece({
name: 'name of the piece here',
piece: ThePieceClass
store: 'name of the store'
})
import { container } from '@sapphire/framework';
container.stores.loadPiece({
name: 'name of the piece here',
piece: ThePieceClass
store: 'name of the store'
})
This is also how built in pieces are loaded so no fs operations are required: - https://github.com/sapphiredev/framework/blob/9b42bcd2041bd440d8d8d3da62bc362d588e5a56/src/arguments/CoreBoolean.ts#L24-L28 - https://github.com/sapphiredev/framework/blob/main/src/arguments/_load.ts - https://github.com/sapphiredev/framework/blob/9b42bcd2041bd440d8d8d3da62bc362d588e5a56/src/lib/SapphireClient.ts#L22
Teixeira
TeixeiraOP•2mo ago
Awesome this is exactly what I'm looking for
Favna
Favna•2mo ago
or if you want to do this for all pieces set baseUserDirectory to null where is the guide page
Favna
Favna•2mo ago
Sapphire Framework
Registering and loading virtual pieces | Sapphire
Virtual pieces differ from normal pieces in that they are not loaded from the file system. Instead, they are registered
Teixeira
TeixeiraOP•2mo ago
By the way since I have you here... This is related to something I'm trying to do for emojis after setting up your package @favware/discord-application-emojis-manager. I followed up on the message from your private server "Favware", not sure if you've seen it https://discord.com/channels/512303595966824458/512635182797291520/1297344404935151667
Favna
Favna•2mo ago
I did see it, I didnt reply to it yet
Teixeira
TeixeiraOP•2mo ago
I want to load the emojis based on their names, and since I'm then using these custom emojis on some of my pieces, I want to make sure they're loaded before I start receiving events/commands Think I should be able to do it with this but wanted to sanity check I'm not stupidly overthinking this and there's a much easier way to do it 😅
Want results from more Discord servers?
Add your server