Is there a way to prevent fetching information both in the precondition and the command itself?

I need to fetch the same data to resolve a precondition, as I'll need later in the command. Is there a way to prevent fetching this twice?
4 Replies
Lioness100
Lioness1002y ago
No, not with preconditions. I was thinking about something like it a while ago but never got the time to work on it and forgot https://discord.com/channels/737141877803057244/737142774738190377/1024108953577201734 If you want to be really really hacky, you could also attach something to the interaction object directly, as that's reused between preconditions and the command kind of like how you would assign to req in an expressjs middleware
Gavan
GavanOP2y ago
@Lioness100 Ok, thanks! For the time being I just kinda invented a new 'guard' primitive for myself and am doing things like
public async chatInputRun(interaction: Command.ChatInputInteraction) {
...
if(!await guardIsValidTopic(interaction, topicResult)) return;
public async chatInputRun(interaction: Command.ChatInputInteraction) {
...
if(!await guardIsValidTopic(interaction, topicResult)) return;
Lioness100
Lioness1002y ago
👍
Krish
Krish2y ago
you can also make an object which will store the response according to the interaction id and reusing it in your command, and finally remove the entry from the object
Want results from more Discord servers?
Add your server