Skip to content

How to require joining chats?ΒΆ

Do you want to require users to join channels or groups? In this guide, we'll explain how to do it, step by step.

For this guide, we'll require users to join 2 channels when they start the bot, i.e., when they send /start. However, you can use this feature anywhere in the bot, not just in /start.

We'll show a message to users when they start the bot, telling them they must join the channels, along with a button they must press to verify that they have joined. The final result will look like this:

Require Subscription in Chat in VisualMaker

Here's how it works: the message will be shown to the user whenever they send /start. When they click the βœ… Verify βœ… button, the bot will check if the user is joined to the channels. If not, the message will be shown again, and this process will continue until the user joins. Once joined, the main menu of the bot will be displayed.

Let's go step by step:ΒΆ

  1. First, add your bot as an administrator to the channels you want to require users to join.
  2. Now, enter the editor mode of your bot by clicking the πŸ›  Edit button, and send /start to edit the command. Then click πŸ’¬ Message and add the message that will be shown in the main menu of the bot (if you don't have one yet). For example: "Welcome to the bot." This will help illustrate this guide better. It's also recommended to have at least one button in the bot.
  3. While editing /start, click on Actions 🌟.
  4. Add an action of Send message, click on Configure πŸ› , and save the message that will ask users to join the channels. For example, I've saved the following message: VisualMaker configure send message

  5. Then, within the same action, click on πŸ’  Deploy keyboard πŸ’ , then on πŸ”˜ Create new keyboard πŸ”˜, select πŸ”· Normal, and send the name of the button to be created, in this case it will be βœ… Verify βœ…. This will display the button when sending the message.

  6. Next, add a Wait for answer action, so the bot waits for the user to press the button, as the button is a message. You don't need to configure the action, just activate it.
  7. Then add a Chat member action and configure it. Click on the πŸ“ Set chats πŸ“ button and send the IDs or @usernames of your channels to verify, separated by a comma. I'll send the @usernames, which are @channel_of_cats, @channel_of_dogs.

    VisualMaker configure member in chat 1 VisualMaker configure member in chat 2

    As you can see, each chat has been assigned a number, according to the order in which it was saved. It's important to remember this for later.

  8. Go back to your list of actions and add a Add condition action, configure it. Click on πŸ” New condition πŸ”Ž, here we must enter the expression to evaluate, save the following:

    {is_inside(#CmfwA.chat1.status#, ("member", "administrator", "owner")) and is_inside(#CmfwA.chat2.status#, ("member", "administrator", "owner"))}

    Replace CmfwA with the ID of your Chat member action added in step 6, in my case it's CmfwA, but in yours it'll be different. Notice that it must be replaced twice in the expression.

    Now let's analyze the expression in detail:

    • First, all expressions are inside braces { }.
    • We've also used the is_inside() function, which checks if the first argument is inside the second argument.
    • To understand better, let's analyze the first use of is_inside():

      is_inside(#CmfwA.chat1.status#, ("member", "administrator", "owner"))
    • The first argument would be #CmfwA.chat1.status#.

    • And the second argument would be ("member", "administrator", "owner"), as you can see, it's enclosed in parentheses, meaning it's a tuple.
    • What the function does is check if what's passed in the first argument is inside the elements of the second argument.
    • chat1 refers to the first saved channel, remember that we told you to remember it before. In my case, it's @channel_of_cats, as you can see in the image above.
    • Also, remember that status returns the user's status in the chat, which can be member, administrator, owner, left, banned, restricted. You can see all of this in more detail in the article dedicated solely to the Chat member action.
    • Therefore, this first part of the expression can be translated as: If the current user's status in the @channel_of_cats channel is a member, administrator, or owner, the condition is true; otherwise, it's false.
    • In the second part of the expression, we see almost exactly the same as the first part, with the only difference being that instead of chat1, it's now chat2, meaning that the second saved channel is being evaluated, which in my case is @channel_of_dogs, as you can see in the image above.
    • Both evaluations are separated by and, which means that the condition will only be true if both evaluations are true, in other words: the condition will only be true if the user is a member, administrator, or owner of both channels.
  9. Once the expression is saved and understood, we only need to specify what will happen if the condition is true and if it's false.

  10. Click on the πŸ‘ If true, then click βœ… Continue. This tells it to continue if the condition is true (if the user is joined to both channels), which in this case, with no more actions, means it will go to the main menu of the bot.
  11. Click on If false πŸ‘Ž, then click πŸ†” Execute action by ID πŸ†”, copy the ID of the Send message action from step 4, and paste it here, make sure it's selected ➑️ After action: continue ⏩.

    In my case, it looks like this:

    VisualMaker configure member in chat condition

    What have we done here? Firstly, we've told it that if the condition is false, i.e., if the user hasn't joined both channels, execute the Send message action that shows the message asking the user to join the channels, and then continue with the rest of the actions that follow. Thus, it continues in a loop that only exits when the user joins the channels.

  12. Don't forget to activate all the actions.

And that's it! With this, you'll require your users to join your channels before they can use the bot.

My actions look like this:

VisualMaker configure member in chat condition

It's important to mention that all of this is fully customizable to your liking. For example, in step 11, instead of executing the Send message action that displays the message asking the user to join the channels, you could execute another Send message action, but isolated by a separator, which would send a message telling the user that they haven't joined, and from there, you could create a Jump to action action to return to the Chat member action and verify again if the user has joined.

You could also add a Add condition action at the beginning to check if the user is new to the bot through their primitive variable is_new, and if they are new, require them to join the channels, but if they aren't new, send them directly to the main menu.

Another thing you could do is create the βœ… Verify βœ… button as a inline keyboard, although that is a bit more complex.

The possibilities are endless, and it's up to you, as a bot creator, to play with all the power that VisualMaker puts in your hands.