Package com.dianxin.tori.api.commands
Class CommandRegistrar
java.lang.Object
com.dianxin.tori.api.commands.CommandRegistrar
The central registrar for all Discord interactions including Slash Commands,
User Context Menus, and Message Context Menus.
This class handles loading the commands into the bot's memory, validating their annotations/metadata, committing them to the Discord API, and routing incoming interaction events to their respective execution classes.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcommitAllCommands(@Nullable net.dv8tion.jda.api.entities.Guild guild) Commits all registered commands (Slash, User Context, Message Context) to the Discord API.voidonMessageContextEvent(net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent event) Routes an incoming message context menu event to the appropriate registered handler.voidonSlashCommandEvent(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent event) Routes an incoming slash command event to the appropriate registered command handler.voidonUserContextEvent(net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent event) Routes an incoming user context menu event to the appropriate registered handler.registerMessageContext(BaseMessageContextMenu... contextMenus) Registers one or more base message context menus.registerMessageContext(ModernBaseMessageContextMenu... contextMenus) Registers one or more modern message context menus.registerSlash(BaseCommand... cmdInstances) Registers one or more legacy slash commands into the system.registerSlash(ModernBaseCommand... cmds) Registers one or more modern slash commands into the system.registerUserContext(BaseUserContextMenu... contextMenu) Registers one or more base user context menus.registerUserContext(ModernBaseUserContextMenu... contextMenu) Registers one or more modern user context menus.setReplyConfig(CommandReplyConfig config) Sets the custom reply configuration for command interactions.
-
Constructor Details
-
CommandRegistrar
-
-
Method Details
-
setReplyConfig
Sets the custom reply configuration for command interactions.This configuration allows developers to customize the messages sent by the registrar when command requirements—such as those defined by annotations like
@OwnerOnlyor@RequirePermissions—are not met.- Parameters:
config- TheCommandReplyConfiginstance containing the custom messages.- Returns:
- This
CommandRegistrarinstance to allow for method chaining.
-
registerSlash
Registers one or more legacy slash commands into the system.- Parameters:
cmdInstances- An array ofBaseCommandinstances to register.- Returns:
- This
CommandRegistrarinstance for method chaining. - Throws:
IllegalStateException- If commands have already been committed to Discord.IllegalArgumentException- If a command does not implementMaincommandRegistry.
-
registerSlash
Registers one or more modern slash commands into the system.- Parameters:
cmds- An array ofModernBaseCommandinstances to register.- Returns:
- This
CommandRegistrarinstance for method chaining. - Throws:
IllegalStateException- If commands have already been committed to Discord.IllegalArgumentException- If a command does not implementMaincommandRegistry.
-
registerUserContext
Registers one or more base user context menus.- Parameters:
contextMenu- An array ofBaseUserContextMenuinstances.- Returns:
- This
CommandRegistrarinstance for method chaining. - Throws:
IllegalStateException- If commands have already been committed.
-
registerUserContext
Registers one or more modern user context menus. Modern context menus rely on theContextMenuannotation for metadata.- Parameters:
contextMenu- An array ofModernBaseUserContextMenuinstances.- Returns:
- This
CommandRegistrarinstance for method chaining. - Throws:
IllegalStateException- If commands have already been committed, or if the interaction name is empty.MissingAnnotationException- If the requiredContextMenuannotation is absent.
-
registerMessageContext
Registers one or more base message context menus.- Parameters:
contextMenus- An array ofBaseMessageContextMenuinstances.- Returns:
- This
CommandRegistrarinstance for method chaining. - Throws:
IllegalStateException- If commands have already been committed.
-
registerMessageContext
Registers one or more modern message context menus. Modern context menus rely on theContextMenuannotation for metadata.- Parameters:
contextMenus- An array ofModernBaseMessageContextMenuinstances.- Returns:
- This
CommandRegistrarinstance for method chaining. - Throws:
IllegalStateException- If commands have already been committed, or if the interaction name is empty.MissingAnnotationException- If the requiredContextMenuannotation is absent.
-
commitAllCommands
public void commitAllCommands(@Nullable @Nullable net.dv8tion.jda.api.entities.Guild guild) Commits all registered commands (Slash, User Context, Message Context) to the Discord API.If a guild is provided, the commands are registered instantly to that specific guild. If the guild is
null, they are registered globally (which may take up to an hour to cache on Discord's end).- Parameters:
guild- The targetGuildto register commands to, ornullfor global registration.
-
onSlashCommandEvent
public void onSlashCommandEvent(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent event) Routes an incoming slash command event to the appropriate registered command handler.- Parameters:
event- TheSlashCommandInteractionEventtriggered by Discord.
-
onUserContextEvent
public void onUserContextEvent(net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent event) Routes an incoming user context menu event to the appropriate registered handler.- Parameters:
event- TheUserContextInteractionEventtriggered by Discord.
-
onMessageContextEvent
public void onMessageContextEvent(net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent event) Routes an incoming message context menu event to the appropriate registered handler.- Parameters:
event- TheMessageContextInteractionEventtriggered by Discord.
-