fix(commands): stop re-editing slash commands on every startup - #148
Merged
Merged
Conversation
commandComparing read default_member_permissions on ApplicationCommand objects, but discord.js exposes defaultMemberPermissions as a PermissionsBitField. That made every gated slash command look changed on each startup, causing unnecessary Discord API edits and risking rate limits during registerCommands. Co-authored-by: Daan Vrieling <contact@zvapor.xyz>
zVapor-Dev
marked this pull request as ready for review
September 16, 2026 22:51
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.
Bug and impact
PR #130 added
default_member_permissionscomparison incommandComparing, but readexisting.default_member_permissionsfrom discord.jsApplicationCommandcache objects. discord.js stores this asdefaultMemberPermissions(PermissionsBitField), so the comparison always sawnullvs the local"4"string and reported every gated command as changed.Impact: On every bot restart,
registerCommandsunnecessarily edits all permission-gated slash commands (/ban,/kick,/setup, etc.). Under frequent restarts or deploys this spams the Discord application-commands API and can hit rate limits, aborting the registration loop and leaving command sync incomplete.Root cause
Wrong property name when reading cached commands from discord.js (
default_member_permissionsvsdefaultMemberPermissions).Fix
normalizeDefaultMemberPermissions().defaultMemberPermissionsfrom discord.js objects anddefault_member_permissionsfrom local.toJSON()data.Validation
tests/command-comparing.test.jscovering matching permissions, real diffs, and null equivalence.npm test— 51/51 passing.