Skip to content

Support DISCORD_ALLOWED_ROLES for role-based access control #7871

@parimple

Description

@parimple

Feature Description

Allow Discord access control based on Discord roles (e.g., Moderator role) instead of hardcoded user IDs. Currently DISCORD_ALLOWED_USERS only accepts a comma-separated list of user IDs, which requires manual updates when moderator ranks change.

Motivation

Server moderation teams change frequently. Currently when a new moderator is added, someone must manually update DISCORD_ALLOWED_USERS with their Discord user ID. This is error-prone and requires ongoing maintenance.

A role-based approach would let moderators self-serve: grant the role on the server, and access is automatic.

Proposed Solution

Add a new environment variable DISCORD_ALLOWED_ROLES that accepts Discord role IDs:

DISCORD_ALLOWED_ROLES=1493705176387948674
DISCORD_ALLOWED_USERS=413720629

Behavior:

  1. If DISCORD_ALLOWED_ROLES is set, resolve the configured roles to members via the Discord API
  2. Check if the message author has any of the allowed roles
  3. Both DISCORD_ALLOWED_USERS and DISCORD_ALLOWED_ROLES can coexist (union)
  4. Resolved role memberships are cached and refreshed periodically (e.g., on gateway restart or on interval)

Implementation notes:

  • Use Discord Guild API to resolve roles to member lists
  • Placeholder for non-numeric entries in DISCORD_ALLOWED_USERS already exists: _resolve_allowed_usernames()
  • A similar _resolve_allowed_roles() method could follow the same pattern

Alternatives Considered

  • Sync script — Run an external cron job that syncs role members to DISCORD_ALLOWED_USERS. Works but adds operational complexity and a delay between granting role and granting access.
  • Bot mention + role check — Keep current mention-based auth but check roles regardless of user ID. Doesn't solve the maintainability problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions