Skip to content

fix(commands): stop re-editing slash commands on every startup - #148

Merged
zVapor-Dev merged 1 commit into
mainfrom
cursor/critical-correctness-bugs-command-perms
Sep 16, 2026
Merged

zVapor-Dev merged 1 commit into
mainfrom
cursor/critical-correctness-bugs-command-perms

Conversation

@cursor

@cursor cursor Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

PR #130 added default_member_permissions comparison in commandComparing, but read existing.default_member_permissions from discord.js ApplicationCommand cache objects. discord.js stores this as defaultMemberPermissions (PermissionsBitField), so the comparison always saw null vs the local "4" string and reported every gated command as changed.

Impact: On every bot restart, registerCommands unnecessarily 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_permissions vs defaultMemberPermissions).

Fix

  • Normalize both sides to comparable string bitfields via normalizeDefaultMemberPermissions().
  • Read defaultMemberPermissions from discord.js objects and default_member_permissions from local .toJSON() data.

Validation

  • Added tests/command-comparing.test.js covering matching permissions, real diffs, and null equivalence.
  • npm test — 51/51 passing.
Open in Web View Automation 

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
zVapor-Dev marked this pull request as ready for review September 16, 2026 22:51
@zVapor-Dev
zVapor-Dev merged commit 8f874bd into main Sep 16, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants