Precondition results

Can we use a different error class besides UserError in the precondition's error method? Might seem like a dumb question, but the last time I attempted it result couldn't unwrap the error
4 Replies
Favna
Favna2w ago
you could throw your own error and not use this.error yes but there really should be no reason to at all. I don't know what problem you were having but I've never faced such a problem. It's very easy to handle precondition errors. Just create a listener called <type of command>Denied and the error is right there, no need to unwrap it or anything. https://github.com/favware/bloombot/blob/main/src/listeners/commands/chatInputCommands/chatInputCommandDenied.ts https://github.com/favware/bloombot/blob/main/src/lib/util/functions/deniedHelper.ts
dan
danOP2w ago
No no, I get what you mean. The error actually originated from sapphire's core pre message run listener, not from my own listener.. idk why but my custom class made it so result couldn't unwrap the error. It was quite the strange error and I never understood why it didn't work My only reason is that I pass some extra things to precondition errors, and I'd like to have better type safety than just using as ExampleInterface on the context
Favna
Favna2w ago
that is either a very old bug from like a year ago or more, or something is wrong somewhere and code to repro the error would be very much appreciated
dan
danOP2w ago
I'll see if I can find the old bot files where this error happened. No promises though since I recently switched laptops and I haven't quite transferred everything properly But alright, I'll try again now. Hopefully it works

Did you find this page helpful?