Commands

Commands are probably the most common way to interact with bots. AckCord comes with a built in commands framework. In use it resembles the API exposed by EventsController (It’s probably more accurate to say the events controller resembles the commands controller). It’s use looks something like this.

import ackcord.commands._
import ackcord.syntax._
import akka.NotUsed

class MyCommands(requests: Requests) extends CommandController(requests) {
  val hello: NamedCommand[NotUsed] = Command
    .named("!", Seq("hello"), mustMention = true)
    .withRequest(m => m.textChannel.sendMessage(s"Hello ${m.user.username}"))
}

Use named to give the command a name. You can also name it later if you don’t name it here. For the execution of the command itself, you have all the same options you had with the events controllers. For simple commands withRequest, which sends the return request of the command automatically, is probably enough.

Like with events we need to register our commands. We do this using an CommandConnector. You can find one at DiscordClient#commands.

val myCommands = new MyCommands(client.requests)
client.commands.runNewNamedCommand(myCommands.hello)

There are many useful CommandBuilders. Make sure to give them all a look.