-
Notifications
You must be signed in to change notification settings - Fork 0
Create a Slash Command
public final class ExampleCommand {}
The value of the @Slash.Tag
will be the tag (or key) you will use to retrieve the command from the SlashClient
. The tag value must be unique.
Note: When retrieving a
SlashCommand
, we use a tag rather than the command's name as a global and a guild command can have the same name.
@Slash.Tag("example")
public final class ExampleCommand {}
When adding the @Slash.Command
annotation, you need to at least define the name and description of the command.
@Slash.Tag("example")
@Slash.Command(
name = "example",
description = "For demonstration purposes only"
)
public final class ExampleCommand {}
The above example would equate in Discord to:
/example
The @Slash.Command
has 4 non-required parameters that you can set to your liking.
-
Option[] options
- the option list of the command -
Subcommand[] subcommands
- the subcommand list of the command -
SubcommandGroup[] subcommandGroups
- the subcommand group list of the command -
boolean enabled
- whether the command is enabled by default when the bot is added to a guild
In the case of the 3 first parameters, only one of them can be set at a time (per command).
For instance, the following is invalid:
// INVALID
@Slash.Command(
name = "example",
description = "An invalid command",
options = { ... },
subcommands = { ... }
)
// VALID
@Slash.Command(
name = "example",
description = "A valid command with options",
options = { ... }
)
// VALID
@Slash.Command(
name = "example",
description = "A valid command with subcommands",
subcommands = { ... }
)
The subcommand groups of a command are defined as follows:
subcommandGroups = {
@SubcommandGroup(
name = "admin",
description = "Edit the admin registry",
subcommands = { ... }
),
@SubcommandGroup(
name = "member",
description = "Edit the member registry",
subcommands = { ... }
)
}
Where the subcommands are non-required parameters.
The options of either a command or a subcommand group are defined as follows:
subcommands = {
@Subcommand(
name = "add",
description = "Add a user",
options = { ... }
),
@Subcommand(
name = "remove",
description = "Remove a user",
options = { ... }
)
}
Where the options are non-required parameters.
The options of either a command or a subcommand are defined as follows:
options = {
@Option(
name = "name",
description = "The name of the user",
type = OptionType.STRING
),
@Option(
name = "age",
description = "The age of the user",
type = OptionType.INTEGER
)
}
Note: The different
OptionType
are:
•STRING
•INTEGER
•BOOLEAN
•USER
•CHANNEL
•ROLE
•MENTIONABLE
- either aMember
or aRole
An @Option
has 2 non-required parameters:
-
boolean required
- whether the option is required or optional -
Choice[] choices
- the choices list of the option
The choices are defined as follows:
@Option(
name = "gender",
description = "The gender of the user",
type = OptionType.STRING,
choices = {
@Choice(
name = "Male",
value = "MALE"
),
@Choice(
name = "Female",
value = "FEMALE"
)
}
)
Note: The only
@Option
types that support choices areOptionType.STRING
andOptionType.INTEGER
.
Note: If the type of the
@Option
isOptionType.INTEGER
, the value of the@Choice
must only contain digits. Otherwise, in the case of theOptionType.STRING
, the value must not have more than 100 characters.
Slash Commands by Robin Mercier • azzerial.net