Embed Replacers

Embed replacers are slightly different as you need to provide replacers for every value that you have replacers setup in the embed in your message.json. The parameter if the message.json value is an embed will instead be an object instead of an array of objects. For the example below we will need to add a replacer for all the text values.

// ./message.json
{
"en": {
...defaultValues,
"SOME_VALUE": {
"embed": {
"author": {
"name": "{AUTHOR_REPLACER}",
"iconURL": "https://discord.com/assets/1cbd08c76f8af6dddce02c5138971129.png"
},
"color": "{COLOR_DYNAMIC}",
"description": "This is an embed description from message.json, {REPLACE_ME}",
"fields": [
{
"name": "{DYNAMIC_FIELD_NAME}",
"value": "This is a test! {VALUE}",
"inline": false
}
],
"footer": {
"text": "This is the footer text! {EXTRA_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, {MORE_TITLE}",
"url": "https://www.google.com"
}
}
}
}
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",
"SOME_VALUE",
"",
{
author_name: [
{
key: "AUTHOR_REPLACER",
replace: message.author.username,
},
],
color: [
{
key: "COLOR_DYNAMIC",
replace: "#FFFFFF",
},
],
description: [
{
key: "REPLACE_ME",
replace: "I have been replaced!",
},
],
fields: [
/* The fields array is slightly different from the rest
as it has you use replacers for each value of each field
for name, value, and inline (none of which are "required").
*/
{
name: [
{
key: "DYNAMIC_FIELD_NAME",
replace: "Some dynamic value!",
},
],
value: [
{
key: "VALUE",
replace: "Hey!",
},
],
},
],
footer_text: [
{
key: "EXTRA_TEXT",
replace: "This is extra text",
},
],
title: [
{
key: "MORE_TITLE",
replace: "This is more title",
},
],
},
);
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",
"SOME_VALUE",
"",
{
author_name: [
{
key: "AUTHOR_REPLACER",
replace: message.author.username,
},
],
color: [
{
key: "COLOR_DYNAMIC",
replace: "#FFFFFF",
},
],
description: [
{
key: "REPLACE_ME",
replace: "I have been replaced!",
},
],
fields: [
/* The fields array is slightly different from the rest
as it has you use replacers for each value of each field
for name, value, and inline (none of which are "required").
*/
{
name: [
{
key: "DYNAMIC_FIELD_NAME",
replace: "Some dynamic value!",
},
],
value: [
{
key: "VALUE",
replace: "Hey!",
},
],
},
],
footer_text: [
{
key: "EXTRA_TEXT",
replace: "This is extra text",
},
],
title: [
{
key: "MORE_TITLE",
replace: "This is more title",
},
],
},
);
return message.channel.send({ embed: message_json_response });
},
});

As you can see from the above code, replacing values in every single field can get extremely space inefficient, so for that reason, it isn't recommended unless you need to do so. The option is just there if you need to use it. Using this feature would also be more efficient if you had dynamic values that needed to be different on every single run, so you could replace part of the message to the updated value. Now, if you were to run the above snippet of code, you should see a new embed that is sent that somewhat resembles the image below.

Note: In general, this feature is only recommended to be used if you want to use multiple languages for your bot, more information here, or you need a dynamic value that also has constant text in it.