Extending EmbedBuilder class

Hello I created this Embed class to always have the same color and footer on my embeds. However, I'd like the setFooter to override only when it's not specified when calling the class. How could I make this ?
const { EmbedBuilder } = require('discord.js');
const { DateNow } = require('./utils');

class Embed extends EmbedBuilder {
constructor(...args) {
super(...args);

super.setColor('ffffff');

super.setFooter({
text: `Influence • ${DateNow}`,
iconURL:
'https://media.discordapp.net/attachments/xxxxxx.png',
});
}
}

module.exports = Embed;
const { EmbedBuilder } = require('discord.js');
const { DateNow } = require('./utils');

class Embed extends EmbedBuilder {
constructor(...args) {
super(...args);

super.setColor('ffffff');

super.setFooter({
text: `Influence • ${DateNow}`,
iconURL:
'https://media.discordapp.net/attachments/xxxxxx.png',
});
}
}

module.exports = Embed;
15 Replies
d.js toolkit
d.js toolkit16mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Looped
Looped16mo ago
You can type the manual fields first then place the ...args so:
constructor(...args) {
super({color: "ffffff", footer: {text: "Influence * ${DateNow}"}}, ...args)
}
constructor(...args) {
super({color: "ffffff", footer: {text: "Influence * ${DateNow}"}}, ...args)
}
Sourceae
SourceaeOP16mo ago
So it means that if in args I have .setFooter this will overwrite the actual footer: {text: "Influence * ${DateNow}"}}
Looped
Looped16mo ago
Iirc it should do so
Sourceae
SourceaeOP16mo ago
DiscordAPIError[50035]: Invalid Form Body
embeds[0].color[NUMBER_TYPE_COERCE]: Value "ffffff" is not int.
DiscordAPIError[50035]: Invalid Form Body
embeds[0].color[NUMBER_TYPE_COERCE]: Value "ffffff" is not int.
I'm getting this error when passing no setColor in the new instance I tried with color not footer yet tried 0xffffff too
Looped
Looped16mo ago
Use the Colors import from discord.js and then use Colors.white
Sourceae
SourceaeOP16mo ago
what if I wanted a custom color ?
Looped
Looped16mo ago
0x didn't work? I believe that's what I use unless I have changed
Sourceae
SourceaeOP16mo ago
I tried 0xffffff and #ffffff too
d.js docs
d.js docs16mo ago
interface ColorResolvable Can be a number, hex string, an RGB array like: ```js (more...)
Looped
Looped16mo ago
The above is the correct syntax
Sourceae
SourceaeOP16mo ago
hex string DiscordAPIError[50035]: Invalid Form Body embeds[0].color[NUMBER_TYPE_COERCE]: Value "0xffffff" is not int.
Looped
Looped16mo ago
Discord.js
Discord.js is a powerful node.js module that allows you to interact with the Discord API very easily. It takes a much more object-oriented approach than most other JS Discord libraries, making your bot's code significantly tidier and easier to comprehend.
Sourceae
SourceaeOP16mo ago
correct syntax was just color: 0xffffff no quote thanks for the help 🙂
Looped
Looped16mo ago
Ah, I thought you removed the quote, my apologies There shouldn't be obe
Want results from more Discord servers?
Add your server