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 message starting with !ping
. In the code part we will type pong!
, so the bot will respond with it.
Using parameters
A crucial feature of the 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 hug 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.
Setup
Parameters can be retrived using the $message function, we will use it to get the user mention:
Result
Here's how the final command should look like:
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.
Let's test different variations:
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:
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 one and regex playgrounds like this one.
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,}>/
You need to add a forward slash before and after your expression, otherwise the bot will only reply when you literally send <@!?\d{18,}>
in your message
Let's try sending some mentions:
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:
Let's see if we get any compliments:
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:
Name | Syntax | Example | Explanation |
---|---|---|---|
Word | word | !ping | Triggers on a message starting with !ping |
Multiple words | word|word... | !ban|!unfriend|!gulag | Fires off on !ban, !unfriend or !gulag |
Case insensitive | word|i | apple|i | Matches 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 bot.
Continue reading
Here are some pages that might come in handy if you still have some doubts about the word trigger: