-
Notifications
You must be signed in to change notification settings - Fork 82
Interactions
In discord's words: Application commands are commands that an application can register to Discord. They provide users a first-class way of interacting directly with your application that feels deeply integrated into Discord.
Setting up an application command is of two stages registering the command and listening to it's events
are a replacement for the text-based commands we used in bots pre-V8; However, the Chat Inputs have a reach interface and interaction system that makes it easier for the user to search for and use the registered commands.
To register a commmand, you may use createGuildChatInputCommand
which registers a command only on a given guild (good for premium features)
or createGlobalChatInputCommand
to register a command on all guilds the bot have the application.commands
scope on.
Code
val kord = Kord(System.getenv("TOKEN"))
kord.createGuildChatInputCommand(
Snowflake(556525343595298817),
"sum",
"A slash command that sums two numbers"
) {
int("first_number", "The first operand") {
required = true
}
int("second_number", "The second operand") {
required = true
}
}
}
You may also give choices for a given command using the choice
function in the DSL Builder which is a set of white listed values for a given arguement.
Code
val kord = Kord(System.getenv("TOKEN"))
kord.createGuildChatInputCommand(
Snowflake(556525343595298817),
"sum",
"A slash command that sums two numbers"
) {
this.
int("first_number", "The first operand") {
required = true
for(i in 0L..9L) {
choice("$i", i)
}
}
int("second_number", "The second operand") {
required = true
for(i in 0L..9L) {
choice("$i", i)
}
}
}