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
Solution:
see the enabled precondition
Jump to solution
26 Replies
Nullified
Nullified•14mo ago
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 😂
Lily Wonhalf
Lily WonhalfOP•14mo ago
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
Nullified
Nullified•14mo ago
And this test mode has to apply to certain commands, deciding if they should run or not?
Lily Wonhalf
Lily WonhalfOP•14mo ago
all of the commands The test mode is simply "if the event you receive is not from the test guild, ignore"
Nullified
Nullified•14mo ago
Okay so basically you can make a monitization pre-condition that does a development mode check and pass/deny it based on that.
Lily Wonhalf
Lily WonhalfOP•14mo ago
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
Nullified
Nullified•14mo ago
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.
Lily Wonhalf
Lily WonhalfOP•14mo ago
Maybe I can make every command extend one of my classes
Nullified
Nullified•14mo ago
You could also make your own command class and extend all your other commands from it.
Lily Wonhalf
Lily WonhalfOP•14mo ago
and I can put the check in there lol
Nullified
Nullified•14mo ago
Same idea 😂 Just append it to the options, e.g.:
Lily Wonhalf
Lily WonhalfOP•14mo ago
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
Nullified
Nullified•14mo ago
public constructor(context: Command.Context, options: Command.Options) {
super(context, {
...options,
['Your-own-precondition', ...options.preconditions ?? []]
});
}
public constructor(context: Command.Context, options: Command.Options) {
super(context, {
...options,
['Your-own-precondition', ...options.preconditions ?? []]
});
}
Something like this, should work I guess 😂
Lily Wonhalf
Lily WonhalfOP•14mo ago
Yeah for the moment It's a bit icky to me >.>
Nullified
Nullified•14mo ago
Technically it's not that different from adding your own functionality by extending SapphireClient, like I do.
vladdy
vladdy•14mo ago
imma need to read all of this first LOL give me a bit
Nullified
Nullified•14mo ago
However I agree a global option would be nice 😂
vladdy
vladdy•14mo ago
iirc we have global preconditions
Solution
vladdy
vladdy•14mo ago
see the enabled precondition
Nullified
Nullified•14mo ago
Oh I must be blind KEKW
Nullified
Nullified•14mo ago
Sapphire Framework
Global preconditions | Sapphire
Sometimes you want a precondition that automatically runs for every command, without having to add it to each command.
Nullified
Nullified•14mo ago
Guess that solves it!
vladdy
vladdy•14mo ago
tehe ya gotta love KEKW
Nullified
Nullified•14mo ago
Sometimes all it takes is for someone to say the right words 😄 That solves it right @Edward ?
Lily Wonhalf
Lily WonhalfOP•14mo ago
I think it does! Thank you! Marking this as solved for now!
ararou!
ararou!•14mo ago
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 nosleep
Want results from more Discord servers?
Add your server