`Precondition` doubts.
Hi, I'm rewriting my bot from Rust's poise framework to Sapphire. In the rust version, there was a config parameter that let me run a check every time, a command is ran. These are regular commands and not slash commands aka
?avatar
. Is there anything similar for Sapphire where I can provide a function that will return either true
or false
to know if the command should be ran or not. Secondly, how do I handle preconditions that may take sometime to execute, something sort of a database lookup which may take from 50-300ms depending on the workload for the bot. I tried doing something like below
But I get the error that the interaction was already replied to. I don't see how I would send a defer reply when running the check and if the check passes, the command's chatInputRun
can use it
interaction response or if it fails pass that error to an external error handler and then respond inside that. Any help is much appreciated.Solution:Jump to solution
Yeah, I recommend deferring it only in precondition and then use editReply or followUp in the command
9 Replies
I didn’t really understand what did you meant, but if you want to do check for prefix commands you can run method messageRun
In precondition
But if you still want to use chatInput commands you can run chatInputRun in precondition just like you did
Also defering a reply should be possible, you probably deferred a reply in command too
So you should remove it from the command
Oh sorry I should've clarified, I'm moving everything from prefix commands to slash commands. Also if i defer in the precondition i shouldn't in the command? i.e. the command will reply to the deferred message from the precondition.
Solution
Yeah, I recommend deferring it only in precondition and then use editReply or followUp in the command
Also delete
await it.delete()
from precondition
Lmk if it worksAh this works now thanks! For the first part of the post, will I have to make a
Precondition
which will run before the command is actually run? In the rust version it looked something like this, the check was at the framework level instead of individual command level.
I don't mind that approach just wondering if there's another method
Yeah, preconditions are ran before the commands are run
I hope I explained it you well and you understand
Preconditions are explained really good on guide so you should check that
Yeah I understand it now, thanks.
idk what msg to mark as answer tho
This one
That was your problem