Dynamic Language Support

Now to actually use these languages, you can either hard type the language that you want to use, or you can use the language command to setup which language you or your guild would like to use, then use the "language" parameter that is passed into all of your commands "run" methods.

JavaScript
TypeScript
JavaScript
// ./commands/Ping.js
const { Command, Validator } = require("cdcommands");
module.exports = new Command({
...commandOptions,
run: ({ message, args, client, prefix, language }) => {
const message_json_response = client.defaultResponses.getValue(
"es",
"TESTING",
"",
[],
);
return message.channel.send(message_json_response);
},
TypeScript
// ./commands/Ping.ts
import { Command, Validator } from "cdcommands";
export default new Command({
...commandOptions,
run: ({ message, args, client, prefix, language }) => {
const message_json_response = client.defaultResponses.getValue(
"es",
"TESTING",
"",
[],
);
return message.channel.send(message_json_response);
},
});

The above snippet of code will only ever return the Spanish translation of the json value. If you wish to dynamically get a users language, all you need to do is use the language parameter shown below! All of the database work is done for you behind the scenes!

JavaScript
TypeScript
JavaScript
// ./commands/Ping.js
const { Command, Validator } = require("cdcommands");
module.exports = new Command({
...commandOptions,
run: ({ message, args, client, prefix, language }) => {
const message_json_response = client.defaultResponses.getValue(
language, // The only value that needs to change
"TESTING",
"",
[],
);
return message.channel.send(message_json_response);
},
});
TypeScript
// ./commands/Ping.ts
import { Command, Validator } from "cdcommands";
export default new Command({
...commandOptions,
run: ({ message, args, client, prefix, language }) => {
const message_json_response = client.defaultResponses.getValue(
language, // The only value that needs to change
"TESTING",
"",
[],
);
return message.channel.send(message_json_response);
},
});

Now with the above code, you should get a different response depending on what the server/user language preference is set to! Easy as that.