Allow or prevent command execution
I found this file in the framework: https://github.com/sapphiredev/framework/blob/main/src/listeners/application-commands/chat-input/CorePreChatInputCommandRun.ts
And it very much looks like that's the one responsible for letting commands be executed or not. I want to accomplish something similar, but if I create my own listener for the same event, it will not prevent the commands that are being authorized by the core listener, will it? How would that work?
And how can I accomplish what I want?
Thank you!
GitHub
framework/src/listeners/application-commands/chat-input/CorePreChat...
Discord bot framework built on top of discord.js for advanced and amazing bots. - sapphiredev/framework
26 Replies
Are you talking about preconditions?
If that's the case, iirc preconditions run at the command level, not before a listener is called. Which would be a questionable implementation anyways
Can you give me an example of what exactly you want? Would make it easier to answer 😂
So this is a workaround I'm trying to implement
I have monetization enabled on my bots
the native Discord features
and so I can do things that bots that don't have that enabled cannot do
The problem is that I can't test those features on another bot token, because I need the monetization to be enabled to be able to test
so I can only test on the prod token
What I would like to have is a "test mode" where I can start the bot in such a way that it only handles events coming from the test guild
I can already do that with every single listener, but the listener responsible for executing commands is inside the framework core so
I'm trying to find a way to do it
And this test mode has to apply to certain commands, deciding if they should run or not?
all of the commands
The test mode is simply "if the event you receive is not from the test guild, ignore"
Okay so basically you can make a monitization pre-condition that does a development mode check and pass/deny it based on that.
I don't want to have to add a precondition on each one of my commands x_x
I want a higher level way to do it
Hmm, well besides the fact that's it should be a single line in every command file;
I have not tried/needed this, for now all I can think of is making your own handler for interactions but this would probably break some other stuff.
Maybe I can make every command extend one of my classes
You could also make your own command class and extend all your other commands from it.
and I can put the check in there
lol
Same idea 😂
Just append it to the options, e.g.:
But yeah I feel like there should be a way to do that @vladdy nah? 👀
^ meaning maybe add smth to the framework yknow uwu
like a global precondition system
idk
Something like this,
should work I guess 😂
Yeah for the moment
It's a bit icky to me >.>
Technically it's not that different from adding your own functionality by extending SapphireClient, like I do.
imma need to read all of this first LOL give me a bit
However I agree a global option would be nice 😂
iirc we have global preconditions
Solution
see the enabled precondition
Oh I must be blind
Sapphire Framework
Global preconditions | Sapphire
Sometimes you want a precondition that automatically runs for every command, without having to add it to each command.
Guess that solves it!
tehe
ya gotta love
Sometimes all it takes is for someone to say the right words 😄
That solves it right @Edward ?
I think it does! Thank you!
Marking this as solved for now!
i've been actually needing this since the test bot of a project ive been working on in the main guild and the owner gave it fucking admin so everyone could use it