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

Fix failure where launch type command is found and can't sync. #4

Merged
merged 4 commits into from
Aug 16, 2024

Conversation

tjsr
Copy link
Contributor

@tjsr tjsr commented Aug 12, 2024

When we try to sync existing commands, it will iterate through the ones returned and already recognised by this discord app, and may return command such as launch - which has a type/index of 4. This goes out of range, so crashes the parse command when it tries to set this within a map that doesn't exist.

For now the simple solution will be to just put a null check on that array index in case you get any unknown command types come back - eg, new features that have come along since this library was written, as is the case here.

But It would also be a good idea to not only have these checks, but update the library to use the latest ApplicationCommandType definitions that include these new unrecognised types.

@ssMMiles
Copy link
Owner

Thanks for the PR :)

I think we'd probably want to warn the user about the failure there rather than just silently skip over it to avoid confusion, are there docs somewhere I've missed for the new command types or not yet?

@tjsr
Copy link
Contributor Author

tjsr commented Aug 16, 2024

I was going to put a log warn in, but didn't know if you prefer to keep the code clean from that kind of thing etc - I didn't see many other places where you log output so was trying not to break that consistency. I definitely agree that are 'more correct' ways, this PR just simply stops it crashing completely but agree that maybe being completely silent about it is bad.

On docs

As far as the docs no - I actually also just spent the last 20 minutes or so trying to find it in the source code, and could not.

ApplicationCommandType for v10 is defined in https://github.com/discordjs/discord-api-types/blob/147e459a16c8b0e15a0dd50f75d62c6dd9098815/payloads/v10/_interactions/applicationCommands.ts#L114C13-L114C36 and also contains only the three types you have in your source. However when I retrieved the command list from the server it did have a longer description. I'll chase it up in the discord devs discord and try to get more info.

I think it was either a command that got created as part of a sample/template app I created - I don't think it's something I could manually have created through the Discord dev portal?

Fix

Long-term, I'd suggest changing this code so you don't just have 3 arrays, but iterate over all the possible types, or storing them another way (each, with a type attribute) - but would want to talk with you before just implementing it any particular way so kept this as minimum as possible.

@ssMMiles
Copy link
Owner

I think leaving it as a simple warning should be fine, anything not expected by the library isn't going to be handled properly anyway and would need the user to update.

@ssMMiles ssMMiles merged commit 5d4914c into ssMMiles:main Aug 16, 2024
1 check failed
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