How can i get registered Command JSON data?

like applicationBuilder.toJSON()?
Solution
Alright, so getting the command JSON in Sapphire is pretty simple.

There isn't one big toJSON() method for everything. The trick is to just make one yourself on each command.

Basically, in your command file, you create a method that just returns its own JSON. You can call it toJSON or whatever you want.

In your command file:
public override registerApplicationCommands(registry: Command.Registry) {
  // Use your new method to register the command
  registry.registerChatInputCommand(this.toJSON());
}

// Then just add this method to return the JSON
public toJSON() {
  return {
    name: this.name,
    description: this.description,
  };
}


Then, in your ready event, you just loop through all your commands and call that method you made.

In your ready event:
client.on('ready', () => {
  const commandStore = client.stores.get('commands');
  const allCommandsJSON = commandStore.map(command => command.toJSON());

  // And now you have an array with the JSON for all your commands
  console.log(allCommandsJSON);
});


And that's it. Now you have an array with all your command JSON data.
Was this page helpful?