Skip to content

Lesson 4 of 9 · 26m

Discord's Permission Model Without Superstition

Model guild permissions, channel overwrites, administrator behavior, and role hierarchy so the bot acts only when Discord truly allows it.

Discord permission bugs are rarely mysterious once you stop treating permissions as a bag of checkbox labels. They are computed authorization state: guild-level role bits, channel overwrite resolution, ownership exceptions, administrator shortcuts, and role hierarchy constraints. If your bot's mental model is "the user has Manage Messages," it will eventually act where it should not or fail where it should succeed.

Compute the effective permission, do not guess it

Every action has an actor, a target, a channel or guild context, and sometimes a hierarchy relationship. In discord.js, use the library's permission resolution rather than hand-rolling bit math for ordinary checks:

const perms = channel.permissionsFor(member);
if (!perms?.has(PermissionFlagsBits.ManageMessages)) throw new Error("missing Manage Messages here");

That answer is channel-specific. ManageMessages in one channel does not imply it in another. Category overwrites, channel synchronization, role overwrites, and member-specific overwrites can all change the result.

Overwrites have an order

A simplified resolution flow is:

start with guild role permissions
apply channel role overwrite denies/allows
apply member overwrite deny/allow
apply ownership/administrator rules

The important operational habit is to reproduce the exact member, role set, channel, and overwrite state when debugging. Telling support "the moderator has the role" skips every interesting part of the problem.

Administrator is not a design shortcut

Administrator bypasses most permission checks. It does not make the bot hierarchy omnipotent, and it does not make your application authorization correct. Granting Administrator because permission debugging is annoying creates a blast radius that includes channel deletion, role management, integrations, and server configuration. For a moderation bot, prefer a precise list:

Manage Channels   slowmode/channel lock operations
Kick Members      remove non-higher members
Ban Members       ban enforcement
Moderate Members  timeouts and member moderation views
Manage Messages   delete or pin messages where required
View Audit Log    evidence correlation, if actually used
Manage Roles      only if the bot assigns roles

Only request Manage Roles if role assignment is a real feature. It is dangerous because a sufficiently placed bot can create privilege escalation paths.

Hierarchy is a second authorization layer

Even with the right permission bit, Discord prevents many actions when the target's highest role is at or above the actor's highest role. The same applies to the bot. A moderator can use your bot as a confused deputy if you check the moderator but forget the bot's own hierarchy position.

if (!target.moderatable) { await interaction.editReply("I cannot moderate that member. Check role hierarchy."); return; }

Permissions change during the workflow

A member may lose a role between opening a modal and submitting it. A channel overwrite may change between queueing and executing an action. Resolve permissions at decision time and again immediately before irreversible execution when the workflow is long-lived.

Field notes

  • Permission bitfields are transport representation. They are not enough application policy by themselves.
  • A successful bot action does not prove the initiating user was authorized; it may only prove the bot was powerful.
  • The guild owner is outside many normal hierarchy assumptions. Never design demos or tests around owner-only behavior.
  • When Discord denies an action, capture permission context. "Missing Access" without context is operationally useless.

Was this lesson helpful?

Sign in to rate