/>help>

Search

Custom Commands

In March 2025, Chattable introduced custom commands to every chat. Custom commands must be declared in your website's code before you initialize your chat and are written in JavaScript. It is important to know that all custom commands are executed on your site and not on Chattable. This allows you to perform any action you want on your website when a command is called in chat. Commands are also specific to each user, meaning the person who runs the command will be the only person that executes the command. It will not execute for every person.

Below, you can see how we add custom commands to Chattable,

chattable.commands = { "test" : function(){ chattable.sendMessage("Hello World!"); } }; chattable.initialize({ stylesheet: "chattable.css" });

In our command above, when a user types !test into the chat it will send a message from that user which reads "Hello World!". We can modify the name of the sender by adding a 2nd parameter to the sendMessage function, like this

chattable.sendMessage("Hello World!", "Bot");

The snippet above will send message to the chat that reads "Hello World!" from "Bot"

Accessing user data

Sometimes while scripting your custom commands, you might want to know things like the invoker's username or user id (uid). You can access these with chattable.user.name and chattable.user.uid.

You can also get the current flair of a user if they have one with chattable.user.flair you can read more about custom user flairs here.

Let's pretend your website has a scoring system. Let's create a command that checks the score of the user and sends it in the chat when a user types !score

chattable.commands = { "score" : function(){ if(score && score > 0){ chattable.sendMessage(`${chattable.user.name}'s score is ${score}`, "Server"); } else { chattable.sendMessage(`${chattable.user.name}'s score is 0`, "Server"); } } }; chattable.initialize({ stylesheet: "chattable.css" });

This code checks if the user has a score and then sends the result to the chat. If the user had their name set to "Andrew" the message could read, "Andrew's score is 0" from "Server"