FluxyAPIFluxyAPI
BlocksDiscord

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.

Bot Permissions

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

FieldRequiredDescription
Bot TokenThe secret variable containing your Discord Bot Token.
Guild IDThe unique ID of the Discord Server (e.g., 123456789012345678).
User IDThe unique ID of the User you want to check.
Output VariableThe 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., 404 if the user is not in the server).

Example

  1. Setup Block:
    • Bot Token: {SEC_MY_BOT_TOKEN}.
    • Guild ID: 883377449922110033.
    • User ID: {request.body.discord_id}.
    • Output Variable: user_data.
  2. Usage: Use a Compare block afterwards to check if {user_data.roles} contains a specific "VIP" role ID.

On this page