Action: Condition¶
The Condition action allows you to add logic to your buttons and commands by evaluating whether something is true or false to decide what to do next. This is useful for controlling who can use a button or command, checking specific values, or customizing the bot's responses based on a situation.
How does this action work?¶
-
Evaluate a condition:
A condition is a logical expression enclosed in curly brackets
{ }
that the bot evaluates. For example:{id == 123456789}
→ Checks if the user ID is123456789
.{balance > 100}
→ Checks if a user's balance is greater than100
.
Note:
id
andbalance
are variables. Learn more about variables here. -
Define what to do based on the result:
- If
True
: What action to take if the condition is met. - If
False
: What action to take if the condition is not met.
- If
How to create and configure the action?¶
1. Create the action¶
- Go to your bot and pressing
🛠 Edit
to enter edit mode. - Select the button or command where you want to add the action, or create a new one.
- Press
Actions 🌟
→🎯 New action
→🧭 Condition
. - Press
Configure 🛠
to set up this action.
2. Configure the options¶
➡️ New condition
¶
The expression to evaluate. It must be enclosed in curly brackets { }
, can use variables and action IDs.
➡️ If true
¶
Choose what to do if the condition is True
:
- Continue: Proceeds to the next action.
- Stop: Ends the execution of the button or command (does not continue to the next actions).
- Execute action by ID: Jumps to a specific action within the current button or command using its
#ActionID#
, allowing you to choose whether tocontinue
with the next actions orstop
after jumping.
➡️ If false
¶
Choose what to do if the condition is False
:
- Continue: Proceeds to the next action.
- Stop: Ends the execution of the button or command (does not continue to the next actions).
- Execute action by ID: Jumps to a specific action within the current button or command using its
#ActionID#
, allowing you to choose whether tocontinue
with the next actions orstop
after jumping.
3. Activate the action¶
Press ✅ Activate
to enable this action.
What does this action return through its ID?¶
This action does not return anything.
Practical example: Secure command to view the date¶
Let's say you want a /view_date
command that displays the current date, but you want to make sure that only you can execute it, even other administrators won't have access.
1. Create the command¶
- Enter editor mode by pressing
🛠 Edit
in your bot. - Create a new command by pressing
✳️ New button | command
and naming it/view_date
. - Go to
Actions 🌟
to configure the actions associated with the command.
2. Configure the actions¶
a) Action 1: Condition¶
- Press
🎯 New action
→🧭 Condition
. - For now, don't configure anything (we'll set it up later).
b) Action 2: Send message¶
- Press
🎯 New action
→✉️ Send message
. -
Press
Configure 🛠
→💬 Set message 💬
and enter the message that will display the date:✅ Administrator verified ✅ The current date is {date_now()}
-
Return to the actions menu and activate the action by pressing
✅ Activate
.
c) Add a separator¶
Press New separator 📍
to add a separator and create a new action block. Learn more about separators.
d) Action 3: Send message¶
- Press
🎯 New action
→✉️ Send message
. -
Press
Configure 🛠
→💬 Set message 💬
and enter the message to show if the user is not you:❌ You do not have permission to use this command.
-
Return to the actions menu and activate the action by pressing
✅ Activate
. - Copy the ID of this action, as you'll need it shortly.
e) Configure the Condition action¶
-
Go back to the
Condition
action (Action 1) and pressConfigure 🛠
:-
New condition:
{id == 123456789}
Replace
123456789
with your own user ID. -
If true: Select
continue
. - If false:
This ensures that only you (the administrator with ID
123456789
) can use the command. -
-
Return to the actions menu and activate the action by pressing
✅ Activate
.
Final result¶
When you send the /view_date
command, the bot will check your ID using the Condition
action:
-
If it's your ID, it continues and shows the current date:
✅ Administrator verified ✅ The current date is 27-01-2025 17:49:40
-
Otherwise, it displays a message saying you don't have permission:
❌ You do not have permission to use this command.
Useful variations¶
-
Role-based verification: You can use a variable to check roles, for example, with a text variable named
roles
that was previously created:{role == "admin"}
-
Conditions with multiple checks:
{balance >= 0 and id != 123456789}
This checks if the balance is greater than or equal to 0 and the ID is not
123456789
.
Important note
You can use any type of expression supported by VisualMaker to create more advanced conditions.