-
Notifications
You must be signed in to change notification settings - Fork 0
Manage a Slash Command
Robin Mercier edited this page Jun 16, 2021
·
3 revisions
Once you have created a Slash Command, the next step is to add it to your bot (application). The process is fairly easy.
When creating the SlashClient, you can register as many commands as you wish. In order do so, add the commands you want to register to the SlashClientBuilder using either:
-
SlashClientBuilder#addCommand(Object)- to register command one by one -
SlashClientBuilder#addCommands(Object...)- if you prefer registering commands in bulk
Tip: You can use call the
SlashClientBuilder#addCommands(Object...)multiple time to group the commands you are registering. This helps in organising the code visually.
Here is an example:
final SlashClient slash = SlashClientBuilder
.create(jda)
.addCommands( // global commands
new GlobalCommand(),
...
)
.addCommands( // bot support guild commands
new PingCommand(),
new RestartCommand(),
...
)
.addCommands( // other guild only commands
new PremiumCommand(),
...
)
.build();It is now time to bring the commands online. Get the command you want to manage by its tag:
final SlashCommand command = slash.getCommand("tag");You can now decide what to do with the command:
- upsert (update or insert) a command
-
SlashCommand#upsertGlobal()- add a command globally -
SlashCommand#upsertGuild(Guild)- add a command to a guild
-
- delete a command
-
SlashCommand#deleteGlobal()- delete a command added globally -
SlashCommand#deleteGuild(Guild)- delete a command added to a guild
-
- retrieve a command privileges
-
SlashCommand#retrieveGlobalPrivileges(Guild)- retrieve the command privileges of a guild (for commands added globally) -
SlashCommand#retrieveGuildPrivileges(Guild)- retrieve the command privileges of a guild (for commands added to guilds)
-
- update a command privileges
-
SlashCommand#updateGlobalPrivileges(Guild, CommandPrivilege...)- update the command privileges of a guild (for commands added globally) -
SlashCommand#updateGuildPrivileges(Guild, CommandPrivilege...)- update the command privileges of a guild (for commands added to guilds)
-
Taking the example from before, we would want to do something like:
// global commands
slash.getCommand("global_command").upsertGlobal();
// bot support guild commands
final Guild supportGuild = ...;
slash.getCommand("ping_command").upsertGuild(supportGuild);
slash.getCommand("restart_command").upsertGuild(supportGuild);
// other guild only commands
final List<Guild> premiumGuilds = ...;
premiumGuilds.forEach(guild -> {
slash.getCommand("premium_command").upsertGuild(guild)
});Slash Commands by Robin Mercier • azzerial.net