Rhys - Is there a way to use preconditions to remo...
Is there a way to use preconditions to remove redundant if checks?
For example:
The expectation there is that guild would be defined, but its type is Guild | None so I have to add if checks to it to make typescript happy
Two alternatives I can think of are:
1. Making something like a 'GuildCommand' class which has a function that takes guild as a parameter, and then extending that class with the other commands
something along the lines of
2. Asserting the type i.e
but then that's not great as I'm losing the typesafety of typescript and ignoring the warning
I'm currently leaning towards approach #1, with treating preconditions more as a runtime check thing for permissions & cooldowns
Looking at the docs again it actually looks like the validation in supposed to happen in the
parse
method, so I suppose you could put the conditional checks there, although then from my understanding you don't get to give error messages to the user3 Replies
Going to keep playing with this but found a solution that works decently
ButtonBaseHandler:
GuildTextChannelButtonHandler
This is layer 1, it now sets up having a parent channel in child classes
ChannelSettingsButtonHandler
edit: realized this was for a different problem than the one above with button setups, whoopsie
So each layer overrides get parse data to extract the data it needs, then the very bottom layer has to call what is in the parse function to have types available throughout it
u can use generics
it works on other interaction types that have the cache type generic
i personally don't see any issue with doing this because the precondition already prevents the command if there is no guild
Ah thanks that's helpful, I think that's what I'm looking for