BlocksDiscord
Add User Role
Automatically assign one or multiple roles to a Discord user.
The Add User Role block enables your workflow to dynamically assign roles to users in a Discord server. This is commonly used for automated onboarding, granting access after a successful payment, or rewarding active users.
Core Concept
Think of this as an automated "Security Desk". When a user meets certain criteria in your flow, the Bot issues them a specific set of "access badges" (roles) so they can enter restricted areas of your Discord server.
Hierarchy Matters
In Discord, a Bot can only assign roles that are lower than its own highest role in the server settings. Ensure your Bot has the Manage Roles permission and is positioned correctly in the role list.
Configuration
| Field | Required | Description |
|---|---|---|
| Bot Token | ✅ | The secret variable containing your Discord Bot Token. |
| Guild ID | ✅ | The unique ID of the Discord Server. |
| User ID | ✅ | The unique ID of the User who should receive the roles. |
| Role IDs | ✅ | A list of one or more Role IDs to assign. |
| Audit Log Reason | — | An optional message that will appear in the Discord Server's Audit Log. |
| Output Variable | ✅ | Stores the result of the operation. |
Output Data
Upon success, the output variable will contain:
{
"message": "Roles added successfully",
"role_ids": ["112233445566778899"],
"user_id": "987654321098765432"
}Error Handling
FIELD_MISSING— Triggered if the Bot Token, Guild ID, or User ID is missing.SECRET_RETRIEVE_ERROR— Triggered if the Bot Token secret cannot be found.INVALID_ROLE_IDS— Triggered if the Role IDs provided are not in a valid list format.API_REQUEST_FAILED— Triggered if the Bot fails to communicate with Discord.DISCORD_ERROR_[code]— Triggered if Discord rejects the request (e.g.,403 Forbiddenif the Bot lacks permissions).
Example
- Scenario: Grant a "Pro" role after a Stripe payment.
- Setup Block:
- Bot Token:
{SEC_DISCORD_BOT}. - Guild ID:
1234567890. - User ID:
{request.body.discord_id}. - Role IDs:
["998877665544332211"]. - Audit Log Reason: "Payment confirmed via Stripe".
- Bot Token:
- Result: The user is instantly given the role in Discord, and the server owner can see the reason in the logs.
