Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate Modal Submit Interactions when cancel pressed first. #8614

Closed
tescher opened this issue Sep 11, 2022 · 4 comments
Closed

Duplicate Modal Submit Interactions when cancel pressed first. #8614

tescher opened this issue Sep 11, 2022 · 4 comments

Comments

@tescher
Copy link

tescher commented Sep 11, 2022

Which package is this bug report for?

discord.js

Issue description

When a V13 modal is shown in response to a button interaction, and the user clicks Cancel the first time, then clicks the original button again, bringing up the modal again, then submits successfully, two modal submit interactions are caught by the awaitModalInteraction collector.

In this code:

        try {
            await request.buttonInteraction.showModal(modal);
        } catch(e) {
            Log.error(e.message);
            throw new RuntimeError(e);
        }
        console.log("After showModal");
        const submittedInteraction = await request.buttonInteraction.awaitModalSubmit({
            time: 60000,
            filter: i => i.user.id === request.userDiscordId,
            }).catch(e => {
                Log.error(e.message);
                // TODO Catch timeout error here
                throw new RuntimeError(e);
            });
        request.address = submittedInteraction.components[0].components[0].value;
        await walletRegister(request, submittedInteraction);

walletRegister gets called twice in the cancel-then-submit scenario. ('request' is just an object used to pass context around).

Code sample

try {
            await request.buttonInteraction.showModal(modal);
        } catch(e) {
            Log.error(e.message);
            throw new RuntimeError(e);
        }
        console.log("After showModal");
        const submittedInteraction = await request.buttonInteraction.awaitModalSubmit({
            time: 60000,
            filter: i => i.user.id === request.userDiscordId,
            }).catch(e => {
                Log.error(e.message);
                // TODO Catch timeout error here
                throw new RuntimeError(e);
            });
        request.address = submittedInteraction.components[0].components[0].value;
        await walletRegister(request, submittedInteraction);

Package version

13.7

Node.js version

16.13.1

Operating system

Ubuntu 20.04

Priority this issue should have

Medium (should be fixed soon)

Which partials do you have configured?

Channel, Message, Reaction

Which gateway intents are you subscribing to?

Guilds, GuildEmojisAndStickers, GuildWebhooks, GuildPresences, GuildMessages, GuildMessageReactions, DirectMessages, DirectMessageReactions

I have tested this issue on a development release

No response

@Jiralite
Copy link
Member

This is not a bug with discord.js. You are simply not handling unique modal submissions.

@Jiralite Jiralite closed this as not planned Won't fix, can't repro, duplicate, stale Sep 11, 2022
@tescher
Copy link
Author

tescher commented Sep 11, 2022

There is only one actual modal submission, i.e. the Submit button was only pressed once. The first time the modal came up the 'Cancel' button was pressed. There should only be one interaction caught by the collector since the Submit button was only pressed once.

@Jiralite
Copy link
Member

I'm afraid repeating the issue won't get you anywhere. This is not a bug with discord.js.

There is only one actual modal submission

A user may have submitted one, but there are two modal submissions in your code in the provided scenario. You wait for a modal submission and expire the collector after 1 minute. Again, you provide no unique trait to your filter other than the user of the interaction being the same.

See #7431 (comment) for a code sample of what you want to do.

If you need further help, you can open a discussion or ask in the Discord server.

@tescher
Copy link
Author

tescher commented Sep 11, 2022

OK, so both running collectors grab submissions off the single Submit button press. I filtered on a UUID and that seemed to solve it. Thanks for your help.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants