Command Config
Use the @CommandConfig annotation to configure the
following settings. You can either annotate a command method directly or annotate the interaction controller class. It
is also possible to set a global command config
at the builder:
Global CommandConfig
JDA-Commands will apply clashing CommandConfigs in the following hierarchy:
CommandConfigmethod annotationCommandConfigclass annotation- global
CommandConfig
Enabled For (Permissions)¶
Sets the Discord Permissions a command will be enabled for. By default, a command
will be enabled for every permission.
Danger
Guild admins can modify these permissions at any time! If you want to enforce permissions or secure a critical command further you should use the permissions system of JDA-Commands. You can read more about it here.
@CommandConfig(enabledFor = Permission.BAN_MEMBERS)
@Command(value = "example")
public void onCommand(CommandEvent event) {...}
Interaction Context Type¶
Sets the InteractionContextTypes
of a command. The default value is InteractionContextType#GUILD.
@CommandConfig(context = {InteractionContextType.GUILD, InteractionContextType.BOT_DM})
@Command(value = "example")
public void onCommand(CommandEvent event) {...}
Integration Type¶
Sets the IntegrationTypes
of a command. The default value is IntegrationType#GUILD_INSTALL.
@CommandConfig(integration = {IntegrationType.GUILD_INSTALL, IntegrationType.USER_INSTALL})
@Command(value = "example")
public void onCommand(CommandEvent event) {...}
NSFW¶
Sets whether a command can only be executed in NSFW channels. The default value is false.
@CommandConfig(isNSFW = true)
@Command(value = "example")
public void onCommand(CommandEvent event) {...}
Scope (Guild & Global Commands)¶
Sets whether a command should be registered as a global or as a guild command. The default value is global.
@CommandConfig(scope = CommandScope.GUILD)
@Command(value = "example")
public void onCommand(CommandEvent event) {...}
When having guild scoped commands you have to use the GuildScopeProvider to
tell JDA-Commands what guilds a command should be registered for.
Let's say we have a paid feature in our bot:
Example
We then need to implement a GuildScopeProvider to only register this command
for guilds that have paid for that feature:
Example
Finally, we have to register our PremiumGuildsProvider either at the builder or by annotating it with @Implementation.
Example
Note
Using the @Implementation annotation requires the guice integration
(shipped by default). You can read more about it here.