-
Notifications
You must be signed in to change notification settings - Fork 0
kord annotations
rawr edited this page Feb 17, 2022
·
2 revisions
It is recommended to follow the gradle or maven build tool guide.
fun main()
{
val client = Kord("<your-token>")
Platforms
.usePlatform<KordCommandPlatform> {
this.use(client) // this sets up the listeners for the command
}
.useWrapper<AnnotationCommandWrapper>() // it is required to call this after usePlatform. this class uses the platform to do certain things
client.login()
}After setting up the platform you are able to register the commands through the same Platforms class, view example beneath.
Platforms.registerCommand(TestCommand)@Command("name|alias1|alias2")
class TestCommand
{
@Default // parent command, uses @Command parameter of parent class.
@CommandPermission("permission")
suspend fun default(executor: KordExecutor, amount: Int)
{
for (i in 0..amount)
{
executor.replyToMessage("iteration $amount")
}
}
@Command("subcommand|subcommandalias1") // subcommand of parent command
@CommandPermission("permission")
suspend fun subcommand(executor: KordExecutor, message: Array<String>)
{
executor.replyToMessage(message.joinToString(" "))
}
}class TestCommand
{
@Command("name|alias1|alias2") // first parent command
@CommandPermission("permission")
suspend fun command1(executor: KordExecutor, amount: Int)
{
for (i in 0..amount)
{
executor.replyToMessage("iteration $amount")
}
}
@Command("command2name|command2alias") // other parent command
@CommandPermission("permission")
suspend fun command2(executor: KordExecutor, message: Array<String>)
{
executor.replyToMessage(message.joinToString(" "))
}
}@Command("hey|how|test")
object TestCommand
{
@Help
@Default
@HelpDescription("Show this menu")
@CommandPermission("hello.test")
suspend fun test()
{
println("called test() body") // this won't print!
}
@Command("bye")
@HelpDescription("Broadcast a message.")
suspend fun bye(executor: KordExecutor, lol: Array<String>)
{
val message = executor.message
executor.replyToMessage("${message.joinToString(" ")} ${message.content}")
}
@Command("yo")
@HelpDescription("Broadcast your name.")
fun yo(executor: KordExecutor, @Value("1") amount: Int)
{
for (i in 0..amount)
{
executor.replyToMessage("iteration $amount")
}
}
}