Work In Progress
This documentation is in beta. It's missing lots of content, search is broken, and many links go nowhere. These problems will be fixed before release, but there's plenty of work left!
Skip to main content

Arguments

Command Types

While most command types support arguments, Context Commands don't. If you need to collect anything from users who run these commands, you'll need to use Modals instead.

Arguments represent the parameters users supply to your commands. You can define arguments by creating a class extending the Arguments type, containing properties created with converter builder functions:

class MyArguments : Arguments() {
val target by user {
name = "target"
description = "Target user"
}
}

Once you've created an arguments class, provide it to your commands' builder functions. This will make the parsed arguments available via the arguments property in your command's action { } block:

publicSlashCommand(arguments = ::MyArguments) {
name = "my-command"

action {
respond {
content = "Target user: ${arguments.user.mention}"
}
}
}

Arguments API

The Arguments type exposes a few settings you can use to configure how Kord Extensions should parse your commands' arguments, among other things.

open class Arguments

Base class you should extend to represent a set of command arguments.

open var parseForAutocompleteType: BooleanDefault: false

Whether to attempt to parse previous arguments when handling an autocompletion event.

When working with Slash Commands and Discord's autocomplete system, setting this to true allows your autoComplete { } blocks to retrieve the value for the other arguments, if the user provides them.

Some converter types provide a default autoComplete { } block, and you'll need to set this property to true when using them.

Show/Hide Internal APIs

The following APIs are intended for internal use, but may be helpful if you're developing your own related libraries.

open arg(...)Returns:Converter<R>

Adds a converter to this class' list of arguments, wrapping it in an Argument object. Used internally by the converter builder functions.

Type Parameters
RType: Any

The data type the given converter returns.

Arguments
displayNameType: Key

Display name shown on Discord, used in help messages, and the key for keyword arguments in Chat Commands.

descriptionType: Key

Description shown on Discord, and used in help messages.

converterType: Converter<R>

Converter object to add.

val argsType: MutableList<Argument>Default: mutableListOf()

List of wrapped converter objects representing command arguments, stored in the order they were defined.

open validate(...)

Validation function called by Kord Extensions, ensuring your arguments classes make sense.

Arguments
localeType: Locale

Resolved locale for the current command execution.