fix(events): prevent double execution of slash commands and components#121
Draft
cursor[bot] wants to merge 1 commit into
Draft
fix(events): prevent double execution of slash commands and components#121cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
…tion
Validators and Guild interactionCreate/components modules each registered
separate client.on('interactionCreate') listeners. Node emits those listeners
concurrently, so slash commands and UI components could run twice before
interaction.replied was set — corrupting economy balances and duplicating side
effects.
Defer Guild interactionCreate modules into a followup chain that runs
sequentially after validators inside the single validations listener.
Co-authored-by: zVapor_ <contact@zvapor.xyz>
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
Slash commands and UI components (buttons, select menus, modals) could execute twice for a single Discord interaction. This caused duplicated economy transfers (e.g.
/rob,/deposit), duplicate replies, and other side effects.Root cause
src/handlers/events.jsregistered three separateclient.on("interactionCreate")listeners:chatInputCommandValidator,buttonValidator, etc. — each calls.run())Guild/interactionCreate.js(also calls.run()for slash commands)Guild/components.js(also calls.run()for buttons/selects/modals)Node.js invokes async event listeners concurrently. The
interaction.replied || interaction.deferredguards in the Guild handlers assumed validators had already finished, but both listeners started before either replied.This regressed when per-module event registration was restored in #67/#72.
Fix
Defer
Guildmodules withevent: "interactionCreate"into aninteractionCreateFollowupschain that runs sequentially after validators inside the single validations listener. Guild handlers still skip via the existingreplied/deferredcheck once validators handle the interaction.Validation
tests/interaction-create-single-listener.test.jsdocumenting the race and asserting the chained registration patterntests/events-handler-shape.test.jsnpm test— 40/40 passing