Skip to content

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?

  1. 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 is 123456789.
    • {balance > 100} → Checks if a user's balance is greater than 100.

    Note: id and balance are variables. Learn more about variables here.

  2. 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.

How to create and configure the action?

1. Create the action

  1. Go to your bot and pressing 🛠 Edit to enter edit mode.
  2. Select the button or command where you want to add the action, or create a new one.
  3. Press Actions 🌟🎯 New action🧭 Condition.
  4. 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 to continue with the next actions or stop 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 to continue with the next actions or stop 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

  1. Enter editor mode by pressing 🛠 Edit in your bot.
  2. Create a new command by pressing ✳️ New button | command and naming it /view_date.
  3. Go to Actions 🌟 to configure the actions associated with the command.

2. Configure the actions

a) Action 1: Condition
  1. Press 🎯 New action🧭 Condition.
  2. For now, don't configure anything (we'll set it up later).
b) Action 2: Send message
  1. Press 🎯 New action✉️ Send message.
  2. Press Configure 🛠💬 Set message 💬 and enter the message that will display the date:

    ✅ Administrator verified ✅
    
    The current date is {date_now()}
    
  3. 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
  1. Press 🎯 New action✉️ Send message.
  2. 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.
    
  3. Return to the actions menu and activate the action by pressing ✅ Activate.

  4. Copy the ID of this action, as you'll need it shortly.
e) Configure the Condition action
  1. Go back to the Condition action (Action 1) and press Configure 🛠:

    • New condition:

      {id == 123456789}
      

      Replace 123456789 with your own user ID.

    • If true: Select continue.

    • If false:
      • Press 🆔 Execute action by ID 🆔.
      • In ➡️ After action:, ensure stop is selected.
      • Enter the action ID you copied earlier (Action 3).

    This ensures that only you (the administrator with ID 123456789) can use the command.

  2. 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.
    

Adding condition action to VisualMaker


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.