Precondition i18n

Per this example here https://www.sapphirejs.dev/docs/Guide/preconditions/global-preconditions is it possible to like use one i18n function for it to work for all them with the message or do I have to take special precautions and check which type it is?
Sapphire Framework
Global preconditions | Sapphire
Sometimes you want a precondition that automatically runs for every command, without having to add it to each command.
Solution:
If so, no, but you don't send messages through the preconditions anyway. You to that through listeners. And you identify the identifier there then send the translated message. See https://github.com/skyra-project/skyra/blob/main/src/listeners/commands/messageCommandDenied.ts for an example.
GitHub
skyra/src/listeners/commands/messageCommandDenied.ts at main · skyr...
A multipurpose Discord Bot designed to carry out most of your server's needs with great performance and stability. - skyra-project/skyra
Jump to solution
8 Replies
Favna
Favna11mo ago
One function to do what
Slime
SlimeOP11mo ago
Oh to translate it Get the localized string
Favna
Favna11mo ago
So you mean translate the message from a precondition denial?
Solution
Favna
Favna11mo ago
If so, no, but you don't send messages through the preconditions anyway. You to that through listeners. And you identify the identifier there then send the translated message. See https://github.com/skyra-project/skyra/blob/main/src/listeners/commands/messageCommandDenied.ts for an example.
GitHub
skyra/src/listeners/commands/messageCommandDenied.ts at main · skyr...
A multipurpose Discord Bot designed to carry out most of your server's needs with great performance and stability. - skyra-project/skyra
Slime
SlimeOP11mo ago
Yeah I got that part it was more like trying to do one function so I don't have to like get the translation in each message Cause it seems in that example that the actual error is sent there and then it's parsed by something else
if(error.identifier === CommandDenied) {

}
if(error.identifier === CommandDenied) {

}
Like I have a chatInputCommandDenied but I would have to extend all 3 then I assume?
Slime
SlimeOP11mo ago
Basically it all sums down me wanting to avoid having to translate message and just do it at the end of banlistcheck
No description
Slime
SlimeOP11mo ago
But I guess it doesn't really matter cause I can just send a string as it's 3 functions, it was just trying to write less code for not much gain Okay I re-read it and it makes sense, thank you. To sum it up just move the translation to the listeners instead and have a hardcoded string here just to know what error.
Favna
Favna11mo ago
Correct
Want results from more Discord servers?
Add your server