ChatCommand

open class ChatCommand<T : Arguments>(val extension: Extension, val arguments: () -> T? = null) : Command

Class representing a chat command.

You shouldn't need to use this class directly - instead, create an Extension and use the chatCommand function to register your command, by overriding the Extension.setup function.

Parameters

extension

The Extension that registered this command.

arguments

Arguments object builder for this command, if it has arguments.

Inheritors

Constructors

Link copied to clipboard
constructor(extension: Extension, arguments: () -> T? = null)

Properties

Link copied to clipboard
open var aliasKey: Key?

Translation key referencing a comma-separated list of command aliases.

Link copied to clipboard

Translation cache, so we don't have to look up translations every time.

Link copied to clipboard

Whether to allow the parser to parse keyword arguments. Defaults to true.

Link copied to clipboard
open val arguments: () -> T? = null
Link copied to clipboard
open var description: Key

A description of what this function and how it's intended to be used.

Link copied to clipboard
open var enabled: Boolean

Whether this command is enabled and can be invoked.

Link copied to clipboard

The extension object this command belongs to.

Link copied to clipboard
open var hidden: Boolean

Whether to hide this command from help command listings.

Link copied to clipboard
val kord: Kord

Kord instance, backing the ExtensibleBot.

Link copied to clipboard

When translated, whether this command supports locale fallback when a user is trying to resolve a command by name in a locale other than the bot's configured default locale.

Link copied to clipboard
open override var locking: Boolean

Set this to true to lock command execution with a Mutex.

Link copied to clipboard
open override var mutex: Mutex?

Mutex object to use for locking.

Link copied to clipboard
open lateinit var name: Key

The name of this command, for invocation and help commands.

Link copied to clipboard

Translation cache, so we don't have to look up translations every time.

Link copied to clipboard

Chat command registry.

Link copied to clipboard
open val requiredPerms: MutableSet<Permission>

Permissions required to be able to run this command.

Link copied to clipboard

Sentry adapter, for easy access to Sentry functions.

Link copied to clipboard

Bot settings object.

Link copied to clipboard
open var signature: Key?

Provide a translation key here to replace the auto-generated signature string.

Link copied to clipboard

Locale-based cache of generated signature strings.

Link copied to clipboard

Translations provider, for retrieving translations.

Functions

Link copied to clipboard
open fun action(action: suspend ChatCommandContext<out T>.() -> Unit)

Define what will happen when your command is invoked.

Link copied to clipboard
open suspend fun call(event: MessageCreateEvent, commandName: String, parser: StringParser, argString: String, skipChecks: Boolean = false, cache: MutableStringKeyedMap<Any> = mutableMapOf())

Execute this command, given a MessageCreateEvent.

Link copied to clipboard
open fun check(vararg checks: ChatCommandCheck)

Define a check which must pass for the command to be executed.

open fun check(check: ChatCommandCheck)

Overloaded check function to allow for DSL syntax.

Link copied to clipboard
open suspend fun checkBotPerms(context: CommandContext)

Checks whether the bot has the specified required permissions, throwing if it doesn't.

Link copied to clipboard
open suspend fun emitEventAsync(event: CommandEvent<*, *>): Job

Quick shortcut for emitting a command event without blocking.

Link copied to clipboard
open override fun getKoin(): Koin

Get the associated Koin instance.

Link copied to clipboard
open suspend fun getSignature(locale: Locale): String

Retrieve the command signature for a locale, which specifies how the command's arguments should be structured.

Link copied to clipboard

Return this command's aliases translated for the given locale, cached as required.

Link copied to clipboard
open fun getTranslatedName(locale: Locale): String

Return this command's name translated for the given locale, cached as required.

Link copied to clipboard
open suspend fun lock()

Lock the mutex, if locking is enabled - suspending until it's unlocked.

Link copied to clipboard
fun requireBotPermissions(perms: Permissions)
fun requireBotPermissions(vararg perms: Permission)

If your bot requires permissions to be able to execute the command, add them using this function.

Link copied to clipboard
open suspend fun runChecks(event: MessageCreateEvent, sendMessage: Boolean = true, cache: MutableStringKeyedMap<Any>): Boolean

Run checks with the provided MessageCreateEvent. Return false if any failed, true otherwise.

Link copied to clipboard
open fun unlock()

Unlock the mutex, if it's locked.

Link copied to clipboard
open override fun validate()

An internal function used to ensure that all of a command's required arguments are present.

Link copied to clipboard
open suspend fun <T> withLock(body: suspend () -> T)

Lock the mutex (if locking is enabled), call the supplied callable, and unlock.