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 toolkit2y 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
Looped2y 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
SourceaeOP2y ago
So it means that if in args I have .setFooter this will overwrite the actual footer: {text: "Influence * ${DateNow}"}}
Looped
Looped2y ago
Iirc it should do so
Sourceae
SourceaeOP2y 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
Looped2y ago
Use the Colors import from discord.js and then use Colors.white
Sourceae
SourceaeOP2y ago
what if I wanted a custom color ?
Looped
Looped2y ago
0x didn't work? I believe that's what I use unless I have changed
Sourceae
SourceaeOP2y ago
I tried 0xffffff and #ffffff too
d.js docs
d.js docs2y ago
interface ColorResolvable Can be a number, hex string, an RGB array like: ```js (more...)
Looped
Looped2y ago
The above is the correct syntax
Sourceae
SourceaeOP2y ago
hex string DiscordAPIError[50035]: Invalid Form Body embeds[0].color[NUMBER_TYPE_COERCE]: Value "0xffffff" is not int.
Looped
Looped2y 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
SourceaeOP2y ago
correct syntax was just color: 0xffffff no quote thanks for the help 🙂
Looped
Looped2y ago
Ah, I thought you removed the quote, my apologies There shouldn't be obe
Want results from more Discord servers?
Add your server