[Reviewed] feat: Add permission middleware for command access control (Item 3)#50
Open
messiawrq-spec wants to merge 2 commits into
Open
[Reviewed] feat: Add permission middleware for command access control (Item 3)#50messiawrq-spec wants to merge 2 commits into
messiawrq-spec wants to merge 2 commits into
Conversation
Resolves Item IN3PIRE#10 from Issue IN3PIRE#40. Adds `src/middleware/permissions.js` to validate `interaction.member.permissions` against `command.permissions` array. Used inside the interactionCreate event.
TrivCodez
approved these changes
May 15, 2026
Contributor
TrivCodez
left a comment
There was a problem hiding this comment.
Summary
Creates reusable permission validation middleware for checking user permissions before command execution. Good modular design for permission management.
🔴 Critical
- No critical issues - Permission checking logic is correct
🟡 Warnings
| File | Line | Severity | Issue | Fix |
|---|---|---|---|---|
src/middleware/permissions.js |
7 | Low | Empty permissions array [] should probably fail fast or be documented |
Add guard: if (!permissions.length) throw new Error('Permissions array cannot be empty') |
src/middleware/permissions.js |
8 | Medium | Uses interaction.member but doesn't handle case where it's null |
Add null check: if (!interaction.member) return false; |
🟢 Suggestions
- Add JSDoc with example usage showing permission strings format
- Consider adding support for OR logic (user needs ANY of permissions, not ALL)
- Add caching for member permissions to reduce API calls
- Include permission constants export (e.g.,
Permissions.SendMessages) - Add unit tests for edge cases (null member, missing permissions, bot permissions)
✅ Good
- Clean middleware pattern - easy to integrate
- Clear error messages with missing permission names
- Uses Discord.js PermissionFlagsBitfield correctly
- Properly handles admin bypass
- Good separation from command logic
Approved ✅ Ready to merge with minor suggestions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Claims and resolves Item #10 from Issue #40.
Added
src/middleware/permissions.jsto intercept and validate user permissions prior to command execution. Automatically replies with an ephemeral missing permission message if the user doesn't meet the requirement.