Get User Roles
Retrieve a list of all role IDs assigned to a specific user within a Discord server.
The Get User Roles block allows you to check which roles a user has in a specific Discord server (Guild). This is essential for building permission-based workflows, such as checking if a user is a "Premium" member before granting access to an API.
Core Concept
Imagine the Discord server is a club and roles are different types of "membership cards". This block allows your Bot to look at a specific person's wallet and list all the membership cards they are currently carrying.
Your Bot must be a member of the target server and have the Server Members Intent enabled in the Discord Developer Portal to fetch member data.
Configuration
| Field | Required | Description |
|---|---|---|
| Bot Token | ✅ | The secret variable containing your Discord Bot Token. |
| Guild ID | ✅ | The unique ID of the Discord Server (e.g., 123456789012345678). |
| User ID | ✅ | The unique ID of the User you want to check. |
| Output Variable | ✅ | The name of the variable where the roles list will be stored. |
Output Data
The output variable will contain an object with the following structure:
{
"roles": [
"111111111111111111",
"222222222222222222"
],
"user_id": "987654321098765432",
"guild_id": "123456789012345678"
}You can access the list of IDs directly using {your_variable.roles}.
Error Handling
FIELD_MISSING— Triggered if the Bot Token, Guild ID, or User ID is missing.SECRET_RETRIEVE_ERROR— Triggered if the system fails to fetch the Bot Token from your secrets.API_REQUEST_FAILED— Triggered if the Discord API returns an error or is unreachable.DISCORD_ERROR_[code]— Triggered when Discord returns a specific API error (e.g.,404if the user is not in the server).
Example
- Setup Block:
- Bot Token:
{SEC_MY_BOT_TOKEN}. - Guild ID:
883377449922110033. - User ID:
{request.body.discord_id}. - Output Variable:
user_data.
- Bot Token:
- Usage: Use a Compare block afterwards to check if
{user_data.roles}contains a specific "VIP" role ID.
