How to Register a Discord Slash Command via Sapphire without creating a command file

First of All, I am doing this for a private bot.. so i don't care about other people exploiting the bot if the bot is restarted will sapphire load the command registered without creating a file automatically? if not what should be my other approach My specific problem I have a function called OnUpdateDb(Data) that runs as soon as specific things are added or updated in the database. Here is the structure of the Data object:
{
Name: string,
Description: string,
Js: (interaction) => {
// Actual code for the command
interaction.reply("This will be executed every time the command is used (after the command is registered on Sapphire and Discord).");
}
}
{
Name: string,
Description: string,
Js: (interaction) => {
// Actual code for the command
interaction.reply("This will be executed every time the command is used (after the command is registered on Sapphire and Discord).");
}
}
I want the onUpdateDb function to register the command to sapphire and make the command get loaded on sapphire during restarts
OnUpdateDb(Data){

}
OnUpdateDb(Data){

}
Solution:
Looks like you may be looking for https://www.sapphirejs.dev/docs/Guide/commands/application-commands/application-command-registry/advanced/registering-application-commands-outside-a-command and you simply leave out the registry part in the command file itself. You can also load actual commands in memory by simply setting them in the command store map (container.client.stores.get('commands').set('name', data)). See also https://github.com/sapphiredev/pieces/blob/375896b05897da0fbddbfa7a416c4c7f17445bc1/src/lib/structures/Store.ts#L103 for how we normally load files, you'll want to mimick this for in memory loading. Also you're safe to start loading commands in the ready listener.... Slightly before that if you really must by using the plugin hooks but the difference is so minimal that it's probably not worth the effort....
Sapphire Framework
Registering Application Commands outside a Command | Sapphire
You are able to register your application commands inside of their command class, but also outside of the class! Whether
Jump to solution
1 Reply
Solution
Favna
Favna2y ago
Looks like you may be looking for https://www.sapphirejs.dev/docs/Guide/commands/application-commands/application-command-registry/advanced/registering-application-commands-outside-a-command and you simply leave out the registry part in the command file itself. You can also load actual commands in memory by simply setting them in the command store map (container.client.stores.get('commands').set('name', data)). See also https://github.com/sapphiredev/pieces/blob/375896b05897da0fbddbfa7a416c4c7f17445bc1/src/lib/structures/Store.ts#L103 for how we normally load files, you'll want to mimick this for in memory loading. Also you're safe to start loading commands in the ready listener.... Slightly before that if you really must by using the plugin hooks but the difference is so minimal that it's probably not worth the effort. Also note that doing the first bit won't register them to discord yet, only add them to the sapphire registry. You'll have to dig through the sapphire code a bit to see where we call the registry but it's in our CoreReady (built in ready) listener file. You have to call a similar line yourself. Or do as above and register all the data in a plugin hook so sapphire's CoreReady can then pick them up.
Sapphire Framework
Registering Application Commands outside a Command | Sapphire
You are able to register your application commands inside of their command class, but also outside of the class! Whether
Want results from more Discord servers?
Add your server