Word Trigger

Word commands, also known as message commands are executed when the bot receives a text message.

Basic word command

Let's create a word command with a trigger !ping, this means the command will be triggered whenever someone sends a !ping message. In the code part we will type pong!, so the bot will respond with it.

Word example

Member04/02/2024
!ping
Custom Command Bot 04/02/2024
pong!

Using parameters

A crucial feature of word type are parameters. They are data provided when executing the command.

Let's say we had a ?hug command, which users can use to express their feelings towards other users. In that case we would want users to select a user by mentioning him.

Usage

The mention will be the parameter 1, because users will mention their victim right after the ?hug keyword.

Member04/02/2024
?hug @fajfaj

Setup

Parameters can be retrived using the $message function, we will use it to get user mention:

?hug code

Result

Here's how the final command should look like:

Member04/02/2024
?hug @fajfaj
Custom Command Bot 04/02/2024
@Member hugs @fajfaj

Case insensitivity

Sometimes we don't want to bother users with using correct capitalisation.

How does it work?

Case sensivity can be disabled by adding |i after the trigger. In our case ?hello will be changed to ?hello|i

Example

Here's how to make a case insensitive ?hello command, that will respond with a simple Hello @user message.

?hello command

Let's test different variations:

Member04/02/2024
?hello
Custom Command Bot 04/02/2024
Hello @Member!
Member04/02/2024
?HELLO
Custom Command Bot 04/02/2024
Hello @Member!
Member04/02/2024
?HeLLo
Custom Command Bot 04/02/2024
Hello @Member!

Works perfectly!

Multiple words

Sometimes we want the bot to trigger on multiple words, by separating them with |

Let's say we want our Hug command to trigger on: ?hug, ?abrazo, and ?étreinte.

How can we do that?

We can do that with the following trigger:

?hug|?abrazo|?étreinte

Let's test it out:

Member04/02/2024
?hug @fajfaj
Custom Command Bot 04/02/2024
@Member hugs @fajfaj
Member04/02/2024
?abrazo @fajfaj
Custom Command Bot 04/02/2024
@Member hugs @fajfaj
Member04/02/2024
?étreinte @fajfaj
Custom Command Bot 04/02/2024
@Member hugs @fajfaj

Works as expected!

Regex match

The word trigger can also contain regex expressions for various dynamic triggers.

What's regex?

Don't worry if you don't know what it is. Regex is a pretty advanced topic, and is not necessary in most cases.

However if you want to learn more about regex, you can learn it from some internet guides like this oneopen in new window and regex playgrounds like this oneopen in new window.

Ping detector

Regex has thousands of use cases, but here we will discuss using regex to trigger on a mention anywhere in the message.

User mentions

Bots can only see mentions as a string like: <@434342521997492224>, or <@!434342521997492224>, so we have to design our expression to catch this form.

Trigger

Here is the expression which we are going to use:

  • ? - the previous character is optional
  • \d - any number
  • {18,} - the previous character has to appear 18 or more times
/<@!?\d{18,}>/

Ping detector

Let's try sending some mentions:

Member04/02/2024
Hey @fajfaj! How is it going?
Custom Command Bot 04/02/2024
You've pinged someone!
Member04/02/2024
@Mido, have you found your chocolate yet?
Custom Command Bot 04/02/2024
You've pinged someone!

It detects all of them!

Any message

From time to time you may not now what the message content will be, you can make cc trigger to any message sent in a channel.

How does it work?

It can be done using %all% trigger, it makes the command execute regardless of the content.

Message complimenter

Let's make a command which will randomly compliment every sent message to a specific channel.

To randomize the output, we will use $randomText function, and to restrict the channels we will use the Run only in dropdown menu:

Message complimenter

Let's see if we get any compliments:

Member04/02/2024
How is it going?
Custom Command Bot 04/02/2024
Cool message!
Member04/02/2024
Does anyone here have a monkey as a pet?
Custom Command Bot 04/02/2024
Wonderful punctuation!

Amazing, we've just got complimented by the bot automatically.

🎉 Congratulations

If you read all of the information above, you became a real word trigger master!

Summary

As we got through all the examples, here's a summary of the word trigger:

NameSyntaxExampleExplanation
Wordword!pingTriggers on a message starting with !ping
Multiple wordsword|word...!ban|!unfriend|!gulagFires off on !ban, !unfriend or !gulag
Case insensitiveword|iapple|iMatches with apple and any case variations like ApPLe
Regex/RegExp//<@&\d{18,}>/Detects a user mention anywhere in a message
Any message*%all%%all%Triggers on ANY message

One word only!

In word trigger (besides Regex) you are not allowed to put more than one word. All other words are interpreted as parameters, and cannot overlap with the trigger.

Any message*

Using %all% will result in a slight spam of cooldown messages, and might occasionally override your other commands.

We strongly advise you to set the Run only in dropdown menu to specific channel(s).

To get rid of the cooldown messages completely, you can either set a channel slowmode, or get yourself a premium botopen in new window.

Continue reading

Here are some pages that might come in handy if you still have some doubts about the word trigger:

  • !report - word command tutorial
  • $message - loading parameters
  • $msg - to load info about the message