Interaction and Message Function Preconditions
Hey! Is it possible to create function preconditions for both interactions and messages under the same exported decorator? Or do I have create different exports for each of them?
Alternatively, would I be able to create such function precondition that accepts both messages and interactions?
Solution:Jump to solution
Sure, just make sure your function takes an argument that can be both types and determine which it is by using an instanceof check
9 Replies
https://www.sapphirejs.dev/docs/Guide/preconditions/creating-your-own-preconditions
It is indeed possible
Sapphire Framework
Creating your own preconditions | Sapphire
Just as we did in Creating Commands, we will start by creating a preconditions subdirectory in
You use
messageRun
for messages and chatInputRun
for slash commandsYep, this is true but would it be possible too using precondition decorators?
What you mean?
You can create function preconditions to apply preconditions to certain subcommands through decorators. It's found here: https://github.com/sapphiredev/utilities/blob/main/packages/decorators/src/utils.ts#L73
Ohhh that function, I've only ever used it for the rate limits with plugin-api but haven't actually took the time to understand how it works
So sorry I can't be much help there, I'm sure somebody will pitch in soon though
No worries! Thank you for time
Solution
Sure, just make sure your function takes an argument that can be both types and determine which it is by using an instanceof check
I see, thank you!!