Let's go a little beyond the conventional, on this base a resource present in several API server tools was implemented to allow more advanced systems to be developed more easily.
Just like in http routes, we can pass parameters to the customIds of buttons, select menus and modals. See how simple it is:
First let's create a user context command:
With this we can create a Responder that expects any button component that follows this pattern in the customId.
It should start with manage/user and then have two more parameter segments separated by / and starting with :, where the first will be the user id and the second will be an action.
It would look like this: manage/user/:userId/:action
So we can define this pattern and any button where the customId follows it, will be responded by the defined function. You can get the parameters in the second argument of the function.
You can use this feature with any type of Responder, but don't forget that discord has a 100 character limit on customIds.
The createResponder function has an option where you can specify a way to transform the parameters object, which initially has both keys and values that are just strings. Check it out:
Transform the value parameter into a number, so you can use numeric functions