Embeds

The next concept that we would like to cover about your message.json file, is adding embeds directly in your file. To do this, it should be quite simple if you have run your project at least once to allow intellisense in the file to be setup, but we shall give you an example of adding embeds to your file. To do so, we need to set the value as an object, and add the property of "embed", and set its value to an object. For this example we will use the same initial value as above.

// ./message.json
{
"en": {
...defaultValues,
"TEST_COMMAND": {
"embed": {}
}
}
}

If you were to leave the value as an empty object, then you would get an empty embed in return when getting this value. To actually add values, we need to add actual message embed properties to the object. We will provide a simple example for every property.

Note: All properties supported in the embed consist of "author", "color", "description", "fields", "footer", "image", "thumbnail", "timestamp", "title", and "url". Important: The "fields" value will only support from 1 to 25 field objects.

// ./message.json
{
"en": {
...defaultValues,
"TEST_COMMAND": {
"embed": {
"author": {
"name": "Author Name",
"iconURL": "https://discord.com/assets/1cbd08c76f8af6dddce02c5138971129.png"
},
"color": "RED",
"description": "This is an embed description from message.json",
"fields": [
{
"name": "Field Name",
"value": "Field Value",
"inline": false
}
],
"footer": {
"text": "This is the footer text",
"iconURL": "https://discord.com/assets/1cbd08c76f8af6dddce02c5138971129.png"
},
"image": {
"url": "https://discord.com/assets/1cbd08c76f8af6dddce02c5138971129.png"
},
"thumbnail": {
"url": "https://discord.com/assets/1cbd08c76f8af6dddce02c5138971129.png"
},
"timestamp": 343245323523,
"title": "This is a title that goes to google.com",
"url": "https://www.google.com"
}
}
}
}

To fetch this data from your message.json file, you would need to use the same method as shown first, except for the fact that the replacer parameter will need to be an object instead of an array of objects. More information in Replacers.

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(
"en",
"TEST_COMMAND",
"",
{},
); // getValue will now return a MessageEmbed, so you will need to handle it correctly
// depending on how you have your message.json file setup
return message.channel.send({ embed: 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(
"en",
"TEST_COMMAND",
"",
{},
); // getValue will now return a MessageEmbed, so you will need to handle it correctly
// depending on how you have your message.json file setup
return message.channel.send({ embed: message_json_response });
},
});

The above snippet should return a message similar to the one shown in this image.