Creating your first Command
Having created and started your first chabot it’s time to create your first command.
Commands are created within files which are located in the commands
directory defined in the paths
option when creating the chatbot.
For creating a command you will have to simply create a class and export it. The class has to extend a pre-defined class called ChatCommand.
Command Name
Now that be have created a command we need to set it’s name that will be used by any chatter to execute the command.
To set the name of the command we simply set the name property inside our command class to the command’s name.
Running Commands
Once you have set the name of the command it’s time to run the command logic. When an user runs a command, the package will try to execute the run
method from the command with a TwitchContext.
Here is a detailed example of a simple hello world command:
Now when any user sends the command as !hello
the chatbot will reply to the user’s message, mentioning the user.