MessageCommand

abstract class MessageCommand<C : MessageCommandContext<C, M>, M : ModalForm>(extension: Extension, val modal: () -> M? = null) : ApplicationCommand<MessageCommandInteractionCreateEvent>

Message context command, for right-click actions on messages.

Parameters

modal

Callable returning a ModalForm object, if any

Inheritors

Constructors

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

Properties

Link copied to clipboard

Whether to allow everyone to use this command by default.

Link copied to clipboard

Enables or disables the command in DMs.

Link copied to clipboard
lateinit var body: suspend C.(M?) -> Unit

Command body, to be called when the command is executed.

Link copied to clipboard
open var defaultMemberPermissions: Permissions?

Default set of Permissions required to use the command on a guild.

Link copied to clipboard

The extension object this command belongs to.

Link copied to clipboard
val kord: Kord

Kord instance, backing the ExtensibleBot.

Link copied to clipboard

A Localised version of name. Lower-cased if this is a slash command.

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 val modal: () -> M? = null
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

Quick access to the command registry.

Link copied to clipboard
open override 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

Translations provider, for retrieving translations.

Link copied to clipboard
open override val type: ApplicationCommandType

Discord-side command type, for matching up.

Functions

Link copied to clipboard
fun action(action: suspend C.(M?) -> Unit)

Call this to supply a command body, to be called when the command is executed.

Link copied to clipboard
abstract suspend override fun call(event: MessageCommandInteractionCreateEvent, cache: MutableStringKeyedMap<Any>)

Override this to implement your command's calling logic. Check subtypes for examples!

Link copied to clipboard
open fun check(vararg checks: CheckWithCache<MessageCommandInteractionCreateEvent>)

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

open fun check(check: CheckWithCache<MessageCommandInteractionCreateEvent>)

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 doCall(event: MessageCommandInteractionCreateEvent)

Called in order to execute the command.

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 suspend fun firstSentryBreadcrumb(context: C)

If enabled, adds the initial Sentry breadcrumb to the given context.

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

Get the associated Koin instance.

Link copied to clipboard
open fun guild(guild: Snowflake?)

Specify a specific guild for this application command to be locked to.

Link copied to clipboard
open suspend fun handleError(context: C, t: Throwable)

A general way to handle errors thrown during the course of a command's execution.

Link copied to clipboard
fun localise(key: Key, lowerCase: Boolean = false): Localised<String>

Localises a property by its key for this command.

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
fun requirePermission(vararg permissions: Permission)

This will register a requirement for permissions with Discord.

Link copied to clipboard
abstract suspend fun respondText(context: C, message: Key, failureType: FailureReason<*>)

Override this to implement a way to respond to the user, regardless of whatever happens.

Link copied to clipboard
open suspend override fun runChecks(event: MessageCommandInteractionCreateEvent, cache: MutableStringKeyedMap<Any>): Boolean

Override this in order to implement any subclass-specific checks.

Link copied to clipboard
open suspend fun runStandardChecks(event: MessageCommandInteractionCreateEvent, cache: MutableStringKeyedMap<Any>): Boolean

Runs standard checks that can be handled in a generic way, without worrying about subclass-specific checks.

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 and correct.

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.