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

Exceptions

Kord Extensions provides a set of extra exception types, including some we expect you to throw yourself.

All the provided exceptions extend KordExException. This is a sentinel type, and other than extending Exception, it provides no extra functionality on its own.

Functional

The following exceptions don't necessarily represent errors or issues. Rather, they exist for you to throw in your own code when necessary.

Discord Relayed

This is a special exception you can throw in your command and component action blocks, event handlers, and pretty much anywhere else. When thrown, your bot will respond with the message represented by the reason property in whatever the current execution context is.

For example, throwing a DiscordRelayedException in a chat command will make your bot reply-ping whoever invoked that command with the message.

This exception has an alternative constructor that accepts another DiscordRelayedException, copying the reason property from it. You can also extend it to create your own exception types, for convenience.

open class DiscordRelayedException
Constructor Arguments
val reasonType: Key

Translation key representing the message to respond with.


Arguments

open class ArgumentParsingException : DiscordRelayedException

Your bot throws this exception when something goes wrong during command argument parsing.

Constructor Arguments
val reasonType: Key

Translation key representing what went wrong.

val argumentType: Argument?

Current command Argument wrapper object, if any.

val argumentsType: Arguments

Property representing the Arguments object you wrote to contain your command's arguments.

val parserType: StringParser?

For chat commands, the tokenising string parser used.

class InvalidArgumentException

Your bot throws this exception when it has a misconfigured command argument.

Constructor Arguments
val builderType: ConverterBuilder

Converter builder that failed to validate.

val reasonType: String

The validation failure reason.

Commands

class CommandRegistrationException

Your bot throws this exception when it fails to register a command.

Constructor Arguments
val nameType: Key

Name of the command that failed to register.

val reasonType: String

Why registration failed.

class InvalidCommandException

Your bot throws this exception when it has a misconfigured command.

Constructor Arguments
val nameType: Key?

Name of the command that failed to validate.

May be null in some cases — for example, if validation fails because the command has no name.

val reasonType: String

The validation failure reason.

Events

class EventHandlerRegistrationException

Your bot throws this exception when it fails to register an event handler.

Constructor Arguments
val handlerType: EventHandler

Event handler that failed to register.

val reasonType: String

Why registration failed.

class InvalidEventHandlerException

Your bot throws this exception when it has a misconfigured event handler.

Constructor Arguments
val handlerType: EventHandler

Event handler that failed to validate.

val reasonType: String

The validation failure reason.

Extensions

class InvalidExtensionException

Your bot throws this exception when it has a misconfigured extension.

Constructor Arguments
val clazzType: KClass<out Extension>

The invalid extension class.

val reasonType: String

Why the extension is invalid.

Parser Exceptions

All general parsing exceptions extend BaseParserException. This is a sentinel type, and other than extending KordExException, it provides no extra functionality on its own.

Duration Parser

open class DurationParserException : BaseParserException

Base type for all duration parser exceptions.

Constructor Arguments
errorType: Key

Translation key representing what went wrong.

open class InvalidTimeUnitException : DurationParserException

Exception thrown when the parser encounters an invalid time unit.

Constructor Arguments
unitType: String

The invalid time unit.