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:
Sure, just make sure your function takes an argument that can be both types and determine which it is by using an instanceof check
Jump to solution
9 Replies
b1nzee
b1nzee16mo ago
Sapphire Framework
Creating your own preconditions | Sapphire
Just as we did in Creating Commands, we will start by creating a preconditions subdirectory in
b1nzee
b1nzee16mo ago
You use messageRun for messages and chatInputRun for slash commands
Dolliwyx
Dolliwyx16mo ago
Yep, this is true but would it be possible too using precondition decorators?
b1nzee
b1nzee16mo ago
What you mean?
Dolliwyx
Dolliwyx16mo ago
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
b1nzee
b1nzee16mo ago
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
Dolliwyx
Dolliwyx16mo ago
No worries! Thank you for time Prayge
Solution
Favna
Favna16mo ago
Sure, just make sure your function takes an argument that can be both types and determine which it is by using an instanceof check
Dolliwyx
Dolliwyx16mo ago
I see, thank you!!
Want results from more Discord servers?
Add your server