Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Create a command

Emre Kara edited this page Jun 24, 2021 · 1 revision

How do I create commands?

To create a command, you need to use the "CustomCommand" attribute. Here you can set the command name and the priority. You can have multiple possible methods for the same command.

The access modifier doesn't matter.
You can also make the method private, it will still be found by the system.

It is recommended to have static methods as they don't require any instance.
But it is also fine to use non-static methods.
Only consider that the system will then need an instance and create an instance of the class by itself once on register.
So the class needs to have a parameterless constructor (no constructor is the same as having a parameterless constructor).

I want one command to be tried at first, how can I do that?

The CustomCommand attribute accepts a "priority" parameter.
Set a higher value to make a method get tried first.

Example:

[CustomCommand("mycommand")]
public void MyCommand(string a) {}

[CustomCommand("mycommand", 1)]
public void MyCommands(int a) {}

Both these methods could be executed with "/mycommand 5".
But here it makes sense to try the method with int first, so we add a priority higher than the other methods (default is 0).
If we don't do that, the one with string will propably always get executed (because 5 can also be converted to string).

Clone this wiki locally