This tutorial shows how to create and use a custom block.
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.
In this part, we will go over how to create the custom block.
Go to the Components Tab, New Components, and select Custom Block.
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.
Go to the Add Block page and add the Create DM Channel block. This block creates a DM channel to send a message.
In the User ID field, click Insert Variable and select the userId input from the Custom Block Inputs.
Go to the Add Block page and add the Get User block. This block fetches user details.
In the User ID field, click Insert Variable and select the userId input from the Custom Block Inputs.
Go to the Add Block page and add a Send or Edit Text Message block.
In the Channel ID field, click Insert Variable and select the channelID from the Create DM Channel block.
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.
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.
In the second part of the tutorial, we will go over how to integrate the custom block.
Create a new flow and name it DM User.
Set the trigger to Slash Command.
Name the command dm-user.
Press the Grey Button to add options:
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.
Drag the DM User custom block into the flow.
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 after the DM User block.
In the Message Content field:
Turn the reply ephemeral to make it visible only to the user.
Go to a Discord server with your bot and run the /dm-user command. Example:
The bot should respond with:
The user should receive a DM:
Now your bot is ready to send DMs whenever the /dm-user command is used.