RawCommand

abstract class RawCommand(val owner: CommandOwner, val primaryName: String, val secondaryNames: String, val usage: String = "<no usages given>", val description: String = "<no descriptions given>", parentPermission: Permission = owner.parentPermission, val prefixOptional: Boolean = false) : Command

无参数解析, 只会接收原消息链的指令. Java 查看 JRawCommand.

object MyCommand : RawCommand(
MyPluginMain, "name", // 使用插件主类对象作为指令拥有者;设置主指令名为 "name"
// 可选:
"name2", "name3", // 增加两个次要名称
usage = "/name arg1 arg2", // 设置用法,将会在 /help 展示
description = "这是一个测试指令", // 设置描述,将会在 /help 展示
prefixOptional = true, // 设置指令前缀是可选的,即使用 `test` 也能执行指令而不需要 `/test`
) {
override suspend fun CommandContext.onCommand(args: MessageChain) {
}
}

See also

供 Java 用户继承.

简单指令

复合指令

Constructors

Link copied to clipboard
constructor(owner: CommandOwner, primaryName: String, vararg secondaryNames: String, usage: String = "<no usages given>", description: String = "<no descriptions given>", parentPermission: Permission = owner.parentPermission, prefixOptional: Boolean = false)

Functions

Link copied to clipboard
inline suspend fun Command.execute(sender: CommandSender, vararg arguments: Message = emptyArray(), checkPermission: Boolean = true): CommandExecuteResult
inline suspend fun Command.execute(sender: CommandSender, arguments: String = "", checkPermission: Boolean = true): CommandExecuteResult

执行一个确切的指令

Link copied to clipboard
Link copied to clipboard
open suspend fun CommandContext.onCommand(args: MessageChain)
open suspend fun CommandSender.onCommand(args: MessageChain)

在指令被执行时调用.

Link copied to clipboard
inline fun Command.register(override: Boolean = false): Boolean
Link copied to clipboard
inline fun Command.unregister(): Boolean

Properties

Link copied to clipboard

获取所有指令名称 (包含 primaryNamesecondaryNames).

Link copied to clipboard
open override val description: String

指令描述, 用于显示在 BuiltInCommands.HelpCommand

Link copied to clipboard
Link copied to clipboard

指令可能的参数列表.

Link copied to clipboard
open override val owner: CommandOwner

指令拥有者. 通常建议使用插件主类.

Link copied to clipboard
open override val permission: Permission

为此指令分配的权限.

Link copied to clipboard
open override val prefixOptional: Boolean = false

true 时表示 指令前缀 可选

Link copied to clipboard
open override val primaryName: String

主指令名.

Link copied to clipboard
open override val secondaryNames: Array<out String>

次要指令名.

Link copied to clipboard
open override val usage: String

用法说明, 用于发送给用户