Custom Blocks

This tutorial shows how to create and use a custom block.


Video Tutorial


Written Tutorial

This tutorial is divided into two parts: the first part explains how to create the custom block, and the second part demonstrates how to integrate the custom block.

Creating the Custom Block

In this part, we will go over how to create the custom block.

Create the Block

Go to the Components Tab, New Components, and select Custom Block.

Add Inputs

Press the Blue Button to create an input.

In the popup, name the input user id.

Now create another input called message.

Next add a banner to describe the block’s purpose.

Add a Create DM Channel Block

Go to the Add Block page and add the Create DM Channel block. This block creates a DM channel to send a message.

Fill in User ID

In the User ID field, click Insert Variable and select the userId input from the Custom Block Inputs.

Add a Get User Block

Go to the Add Block page and add the Get User block. This block fetches user details.

Fill in User ID

In the User ID field, click Insert Variable and select the userId input from the Custom Block Inputs.

Add a Send or Edit Text Message Block

Go to the Add Block page and add a Send or Edit Text Message block.

Fill in Channel ID

In the Channel ID field, click Insert Variable and select the channelID from the Create DM Channel block.

Fill in Message Content

Click Insert Variable, select Get User, and choose Mention to add the user mention.

Press Enter, then click Insert Variable again, select Custom Block Inputs, and choose message.

Configure Outputs

For that, we need to go into the lower custom block button

Press the Blue Button to create a new output.

Now a popup appears again. Type mention user as the name of the output.

Click Insert Variable, select Get User, and choose Mention to add the user mention.

Now the custom block is complete. To use it, we need to create another flow.

Integrating the Custom Block

In the second part of the tutorial, we will go over how to integrate the custom block.

Set Up the Flow

Create a new flow and name it DM User.

Set the trigger to Slash Command.

Name the command dm-user.

Add Command Options

Press the Grey Button to add options:

Ignore the Red arrow to the Command Name

First Option: Set the type to User and name it user. Check the Required box.

Second Option: Set the type to Text, name it message, and check the Required box.

Click Sync Command to make the command available in Discord.

Add the Custom Block

Drag the DM User custom block into the flow.

Fill in the Inputs

In the userId field, click Insert Variable, select Slash Command, and choose user ID.

In the message field, click Insert Variable, select Slash Command, and choose message.

Add a Text Reply to Interaction Block

Add a Text Reply to Interaction block after the DM User block.

In the Message Content field:

  • Click Insert Variable, select DM User, and choose Mention User.
  • Write “has been sent a DM” after the variable.

Turn the reply ephemeral to make it visible only to the user.

Test Your Command

Go to a Discord server with your bot and run the /dm-user command. Example:

  • /dm-user @username Hello, how are you?

    \

The bot should respond with:

  • @username has been sent a DM

The user should receive a DM:

  • @username Hello, how are you?

Now your bot is ready to send DMs whenever the /dm-user command is used.