Skip to content

Using With JDA

In order to use your newly created Slash Command class, you'll need a SlashCommandClient. Well, how do you get one? Its only constructor is internal. You'll need to get access to it via SlashCommandClient.getInstance(). If you're creating a new client, it can do that too, but only upon initialization. Once there has been one SlashCommandClient created, a new one will never take its place, making the SlashCommandClient a singleton object for the rest of your application's run time.

To use your command objects with the client, you'll need to pass an instance of SlashCommandClientConfig with the commands added to the getInstance() call. If there's already an instance, the value of the passed config is ignored; however if the internal value is not present its set as a new client with the provided config as its config.

If you have no reason to change any of the values exposed in SlashCommandClientConfig, and only need to add your commands, you can call SlashCommandClientConfig justCommands yourCommandList, justCommands taking a Collection value (most any collection type).

A Theoretically Functional Pseudocode Example
val commands = hashSetOf(SayCommand())
jda = JDABuilder.createDefault(token)
    .addEventListener(SlashCommandClient.getInstance(SlashCommandClientConfig justCommands commands))


Please note that Discord can take up to an hour for Slash Commands to update or even appear in the client. (A somewhat decent workaround is to test commands in DM, but that may not be possible for every command you're making.)

Once JDA's ReadyEvent is fired, the SlashCommandClient is initialized by having the command's information being HTTP POSTed by JDA.