Command Handling

A help page for handling commands with the built in commandhandler

Introduction

You don't have to use this commandhandler, it's just a simplification to help you.

Initialising the CommandMap

$discord->enableCommandMap();

This will enable the commandmap functionalities, you have to put this function before any other commandmap action, or it'll throw an Exception.

Registering Prefixes

# enabling the commandmap
$discord->enableCommandMap();

# adding prefixes
$discord->getCommandMap()->addPrefix("-");
$discord->getCommandMap()->addPrefix("->");

You can add a various amount of prefixes with a various length (billions of prefixes might be too large, depending on your RAM ;] )

If you don't add a prefix, the commands won't ever be called

Registering Commands

After enabling the CommandMap and adding one / more prefixes, you should register a Command instance now to make the commandhandler work!

This example registers an anonymous class (you can use normal classes too), I hope the description inside is self-explanatory.

Unregistering Commands

As you can register commands you can also unregister them:

This code will unregister the command sample, you can also pass a Command instance in case you have it.

Last updated