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

feat(Message): Add method to resolve a component by id #6484

Merged
merged 1 commit into from Aug 24, 2021

Conversation

Jiralite
Copy link
Member

Please describe the changes this PR makes and why it should be merged:
Now that the API enforces custom ids to be unique in components in a message, I want to go ahead and propose this new method!

This will add the <Message>.resolveComponent() method. By supplying a custom id, the desired component will be returned (or null if not found). The use case for this is when the desired behaviour is altering the state of some other specific component upon the interaction of a component on the same message. For me, this is altering the .disabled property of a button or a select menu.

I understand I can simply index the components array like so: <ButtonInteraction>.message.components[<number>].components[<number>]. However, I don't think this is quite right. I am assuming that the component I want to edit will always be on a specific row on a specific column. Why should I do this when I have a custom id? Finding a component by a custom id seems like a more intuitive approach, hence why I have this method!

Feel free to suggest/request changes!

Status and versioning classification:

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating
  • This PR changes the library's interface (methods or parameters added)

@ImRodry
Copy link
Contributor

ImRodry commented Aug 21, 2021

This doesn’t allow you to resolve link buttons, why not check for that too?

@Jiralite
Copy link
Member Author

Link buttons don't have a custom id, so there is nothing unique about them. You can have the same structure of a link button for 25 buttons in a message. It's not ideal to have a resolver for something that is not unique (just yet)!

@ImRodry
Copy link
Contributor

ImRodry commented Aug 21, 2021

I was suggesting using the same logic but for the button's URL. I know you can have the same URL in different buttons but I don't see why anyone would do that. You could also add a warning saying it will return the first button with the given URL if a URL is passed.
Alternatively I think you should add some sort of note saying LINK buttons will not work as they do not have customIds

@iCrawl iCrawl added this to the Version 13.2 milestone Aug 21, 2021
@iCrawl iCrawl merged commit 57b94b9 into discordjs:main Aug 24, 2021
@Jiralite Jiralite deleted the componentById branch August 24, 2021 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants