CEEJAYDocs

Revoke a role

Remove a Discord role from a member.

POST /v1/roles/revoke · requires roles:manage

Body parameters

Prop

Type

Behaves exactly like Grant a role in reverse, with the same permission requirements, the same errors and the same 403 when the bot's role is lower than the target role. A member who does not have the role is not an error.

The same roles are rejected as on Grant a role, so a key cannot revoke a moderator, administrator or bot master role from anyone either: see Roles a key can change. The change shows in your server's audit log in Discord with the reason API key: followed by the name of the key.

Returns

Prop

Type

Example

Request
curl -X POST https://ceejay.communitystudios.xyz/api/v1/roles/revoke \
  -H "Authorization: Bearer $CEEJAY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "discordId": "409876543210987654",
    "roleId": "982371004827100394"
  }'

The TypeScript example uses ceejay.roles.revoke from the TypeScript SDK. It returns the data of the response below.

200 OK
{
  "success": true,
  "data": {
    "discordId": "409876543210987654",
    "roleId": "982371004827100394",
    "action": "revoked",
    "duplicate": false
  }
}

Retrying safely

Send an idempotencyKey with every call you might need to retry, such as after a timeout. It is a string of 1 to 128 characters that you choose, sent in the JSON body: an Idempotency-Key header is not read.

  • Retrying with the same key returns the original response. When the same request is sent again with its key, CEEJAY returns the original response, with duplicate: true and the header Idempotent-Replayed: true.
  • Each key is tied to one request payload. The same request means the same member and role. Two requests for one event need two keys, for example match-9:coins and match-9:xp. A key that was used for a different request, here or on any other request of the API, returns 409 with the code idempotency_key_reused, and nothing is changed.
  • A rejected request does not use up the key. A call that was rejected can be retried with the same key once the cause is fixed.
  • A key belongs to the API key that sent it. Another API key of your community can send the same text, and it is a different key.
  • Keys are retained for 30 days. Use a value you can regenerate after a crash, such as an order ID or a match ID.
  • On an instance that does not support idempotency keys yet, a call that sends one returns 503 with the code idempotency_unavailable, and nothing is changed. Community details reports whether keys are supported, under features.retryKeys. idempotency_key is not accepted on this endpoint; use idempotencyKey.
  • Without a key, a retried call is a new call.

Revoking a role is idempotent, so when a first request was started more than a minute ago and never finished, a retry with the same key makes the change again and returns normally. The request is also safe to repeat without a key.

Errors

StatuscodeerrorWhen
400bad_requestThe request body must be a JSON objectThe body is null, text, a number or a list. A request with no Content-Type header is read as text, so it gets this error too
400bad_requestdiscordId must be a valid Discord snowflake (17-20 digits)discordId is missing or is not a string of 17 to 20 digits. A JSON number is rejected
400bad_requestroleId must be a valid Discord snowflake (17-20 digits)roleId is missing or is not a string of 17 to 20 digits
400bad_requestidempotencyKey must be a string of 1-128 charactersThe key is empty, longer than 128 characters or not text, or contains an unpaired surrogate, such as the JSON "\ud800"
400bad_requestidempotencyKey cannot contain a null characterThe key contains a null character (U+0000)
400discord_errorDiscord API error: 400Discord rejected the request. details contains Discord's response
403bot_missing_permissionBot lacks permission to manage this roleThe bot has no Manage Roles permission, or its own role is below the role you named in the role hierarchy
403role_not_allowedRoles that can moderate or manage the server cannot be given or removed through the APIThe role can moderate or manage the server: see Roles a key can change
403role_not_allowedRoles that can mention everyone cannot be given or removed through the APIThe role can mention @everyone, @here and all roles, and your server's @everyone role cannot
403role_not_allowedRoles managed by Discord or by another app cannot be given or removed through the APIThe role is managed by Discord or by another app, such as a bot's own role or the server booster role
403role_not_allowedThe @everyone role cannot be given or removedroleId is your server's own ID, which is the ID of its @everyone role
403role_not_allowedRoles that give access to the CEEJAY dashboard cannot be given or removed through the APIThe role is one of your community's bot master roles
404role_not_foundRole not found in this serverThe role is not one of your server's
404member_not_foundMember or role not found in this serverDiscord found no such member in your server. The role was found a moment before, so the member is not in the server. A member who has only just joined can take up to 15 seconds to be found. Wait 15 seconds before retrying.
409idempotency_key_reusedThis idempotencyKey was already used for a different requestYour API key already used this idempotencyKey for a different request: a request of another kind, or this one with other values. Nothing was changed
409idempotency_in_progressThe first request with this idempotencyKey is still running. Try again in a few seconds.The first request with this key is still being processed. Wait retryAfter seconds and retry
429discord_rate_limitedDiscord API rate limited, try again laterDiscord is rate limiting the bot. retryAfter and the Retry-After header contain the wait Discord requested, in whole seconds, if it gave one. Do not retry in a tight loop
500discord_not_configuredThis instance cannot reach Discord yetThis instance has no connection to Discord yet
503roles_unavailableCould not read this server's roles from Discord, so nothing was changedCEEJAY could not read your server's role list from Discord. Nothing was changed. Retry with a pause between attempts
503discord_unavailableDiscord did not answer in time, so the role may or may not have been taken awayDiscord did not respond to the change within 10 seconds. The change may or may not have been made. The idempotency key stays reserved and the request is safe to repeat
503dashboard_roles_unavailableCould not check whether this role gives access to the CEEJAY dashboard, so nothing was changedCEEJAY could not read your community's bot master roles. Nothing was changed. Retry with a pause between attempts
503idempotency_unavailableidempotencyKey cannot be used on this community yet, so nothing was changedYou sent a key, and this instance does not support idempotency keys yet. Nothing was changed. Community details reports it as features.retryKeys
Discord'sdiscord_errorDiscord API error: 503Any other status Discord returns is passed on, with Discord's own status. details contains Discord's response. After a 5xx the change may or may not have been made

Discord's own rate limit returns 429 with the code discord_rate_limited. That response does not mean your key's own limit is used up: X-RateLimit-Remaining still shows what the key has left.

Every error body also includes requestId, and a 400 with the code bad_request identifies the invalid field in field. Match on code; message text can change.

The errors every request shares (401, 403, 405, 429, 500) are on the Errors page.

Bot permissions

The CEEJAY bot must have Manage Roles and its role must be higher than the target role in the role hierarchy. If it doesn't, this returns 403 with the code bot_missing_permission: move the CEEJAY role higher in Server Settings → Roles.

On this page

Community StudiosPrivacyTerms