encyclopedia embed type thing

hey so i was trying to make a dex or enc for my bot's items and i keep getting this one error: Uncaught DiscordAPIError DiscordAPIError[50035]: Invalid Form Body embeds[0].description[BASE_TYPE_REQUIRED]: This field is required at handleErrors (c:\Users\Moh\Desktop\clutter\Gacha-Bot\bot-20\Tater\node_modules@discordjs\rest\dist\index.js:640:13) at processTicksAndRejections (internal/process/task_queues:95:5) here is any relevant code:
const { ButtonBuilder, ButtonStyle, ActionRowBuilder } = require('discord.js');

async function menuButtons(discordId, message, time, embeds, startPage) {
let page = startPage;

const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('previous')
.setLabel('Previous')
.setStyle(ButtonStyle.Primary)
.setEmoji('◀️'),
new ButtonBuilder()
.setCustomId('next')
.setLabel('Next')
.setStyle(ButtonStyle.Primary)
.setEmoji('▶️'),
new ButtonBuilder()
.setCustomId('delete')
.setLabel('Delete')
.setStyle(ButtonStyle.Danger)
.setEmoji('🗑️'),
);

const pageEmbed = await message.channel.send({ embeds: [embeds[page]], components: [row] });

const filter = (interaction) => {
return interaction.user.id === discordId && ['previous', 'next', 'delete'].includes(interaction.customId);
};

const collector = pageEmbed.createMessageComponentCollector({ filter, time });

collector.on('collect', async (interaction) => {
if (interaction.customId === 'previous') {
page = page > 0 ? --page : embeds.length - 1;
} else if (interaction.customId === 'next') {
page = page + 1 < embeds.length ? ++page : 0;
} else if (interaction.customId === 'delete') {
await pageEmbed.delete();
return;
}

await interaction.deferUpdate();
await pageEmbed.edit({ embeds: [embeds[page]], components: [row] });
});

collector.on('end', async () => {
try {
embeds[page].setColor('#808080'); // Set color to gray
await pageEmbed.edit({ embeds: [embeds[page]], components: [] }); // Remove buttons when time is up
}
catch {
return;
}
});
}
const { ButtonBuilder, ButtonStyle, ActionRowBuilder } = require('discord.js');

async function menuButtons(discordId, message, time, embeds, startPage) {
let page = startPage;

const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('previous')
.setLabel('Previous')
.setStyle(ButtonStyle.Primary)
.setEmoji('◀️'),
new ButtonBuilder()
.setCustomId('next')
.setLabel('Next')
.setStyle(ButtonStyle.Primary)
.setEmoji('▶️'),
new ButtonBuilder()
.setCustomId('delete')
.setLabel('Delete')
.setStyle(ButtonStyle.Danger)
.setEmoji('🗑️'),
);

const pageEmbed = await message.channel.send({ embeds: [embeds[page]], components: [row] });

const filter = (interaction) => {
return interaction.user.id === discordId && ['previous', 'next', 'delete'].includes(interaction.customId);
};

const collector = pageEmbed.createMessageComponentCollector({ filter, time });

collector.on('collect', async (interaction) => {
if (interaction.customId === 'previous') {
page = page > 0 ? --page : embeds.length - 1;
} else if (interaction.customId === 'next') {
page = page + 1 < embeds.length ? ++page : 0;
} else if (interaction.customId === 'delete') {
await pageEmbed.delete();
return;
}

await interaction.deferUpdate();
await pageEmbed.edit({ embeds: [embeds[page]], components: [row] });
});

collector.on('end', async () => {
try {
embeds[page].setColor('#808080'); // Set color to gray
await pageEmbed.edit({ embeds: [embeds[page]], components: [] }); // Remove buttons when time is up
}
catch {
return;
}
});
}
async function createEncEmbed(character, colour) {
const totalStats = character.attack + character.magattack + character.defense + character.magdefense + character.hp + character.speed;
const attachment = (`./CardImages/${character.image}`);

const imageEmbed = new EmbedBuilder();

if (colour) {
imageEmbed.setColor(0x00FF00);
} else {
imageEmbed.setColor(0xFF0000);
}

imageEmbed
.setTitle(`${character.element} ${character.name}`)
.setDescription(character.desc)
.setThumbnail(`attachment://${character.image}`)
.addFields(
{ name: "**Series: **", value: `${character.series}`, inline: false },
{ name: "**Stats: **", value: `Health: ${String(character.hp)}\nAttack: ${String(character.attack)}\nMagic Attack: ${String(character.magattack)}\nDefense: ${String(character.defense)}\nMagic Defense: ${String(character.magdefense)}\nSpeed: ${String(character.speed)}\nTotal Stats: ${String(totalStats)}`, inline: false }
);

return { embeds: [imageEmbed], files: [attachment] };
}
async function createEncEmbed(character, colour) {
const totalStats = character.attack + character.magattack + character.defense + character.magdefense + character.hp + character.speed;
const attachment = (`./CardImages/${character.image}`);

const imageEmbed = new EmbedBuilder();

if (colour) {
imageEmbed.setColor(0x00FF00);
} else {
imageEmbed.setColor(0xFF0000);
}

imageEmbed
.setTitle(`${character.element} ${character.name}`)
.setDescription(character.desc)
.setThumbnail(`attachment://${character.image}`)
.addFields(
{ name: "**Series: **", value: `${character.series}`, inline: false },
{ name: "**Stats: **", value: `Health: ${String(character.hp)}\nAttack: ${String(character.attack)}\nMagic Attack: ${String(character.magattack)}\nDefense: ${String(character.defense)}\nMagic Defense: ${String(character.magdefense)}\nSpeed: ${String(character.speed)}\nTotal Stats: ${String(totalStats)}`, inline: false }
);

return { embeds: [imageEmbed], files: [attachment] };
}
27 Replies
d.js toolkit
d.js toolkit•2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Xu Xiaolan
Xu XiaolanOP•2y ago
const { getAllTemplates, getPlayerCards, getPlayerID } = require("../database.js");
const { createEncEmbed } = require("../utils.js");
const { menuButtons } = require("../menubuttons.js");

module.exports = {
name: "encyclopedia",
description: "Displays all cards",
aliases: ["enc"],
async execute(message, args) {
const playerId = await getPlayerID(message.author.id)

try {
const cardTemplates = await getAllTemplates();
const playerCards = await getPlayerCards(playerId);
const embeds = [];
console.log(cardTemplates.length)
for (let i = 0; i < cardTemplates.length; i++) {
if (playerCards.includes[cardTemplates[i]]) {
colour = true;
}
else {
colour = false;
}
embeds.push(await createEncEmbed(cardTemplates[i], colour));
console.log(embeds)
}

menuButtons(message.author.id, message, 60000, embeds, 0)
} catch (err) {
console.log(err);
message.reply("An error occurred");
}
},
};
const { getAllTemplates, getPlayerCards, getPlayerID } = require("../database.js");
const { createEncEmbed } = require("../utils.js");
const { menuButtons } = require("../menubuttons.js");

module.exports = {
name: "encyclopedia",
description: "Displays all cards",
aliases: ["enc"],
async execute(message, args) {
const playerId = await getPlayerID(message.author.id)

try {
const cardTemplates = await getAllTemplates();
const playerCards = await getPlayerCards(playerId);
const embeds = [];
console.log(cardTemplates.length)
for (let i = 0; i < cardTemplates.length; i++) {
if (playerCards.includes[cardTemplates[i]]) {
colour = true;
}
else {
colour = false;
}
embeds.push(await createEncEmbed(cardTemplates[i], colour));
console.log(embeds)
}

menuButtons(message.author.id, message, 60000, embeds, 0)
} catch (err) {
console.log(err);
message.reply("An error occurred");
}
},
};
i believe the main cause of the errors is just me trying to change the colour of the embeds its supposed to change colour if the user doesn't have the card to be red, and green if the user does have the card i've console log'd my variables and the embeds are post as they should be (atleast it looks like it) so i have no idea where the error is coming from
treble/luna
treble/luna•2y ago
the error originates from your embed description
sexy dark chocolate
You're sending an empty embed, log the embed
Xu Xiaolan
Xu XiaolanOP•2y ago
this is what i get when i log it, is it something with how im returning the embed?
sexy dark chocolate
Can you not view those objects? I'm trying to see what the embed has
Xu Xiaolan
Xu XiaolanOP•2y ago
i dont have a debugger to view the variables it says, is there an extension for it?
sexy dark chocolate
embeds here is an array of objects like these: { embeds: [...], files: [...]} from what your code shows me
Xu Xiaolan
Xu XiaolanOP•2y ago
yeah im trying to make a collection of embeds that the user can go through is the goal
sexy dark chocolate
Then you're doing the wrong thing, here's basically what you're doing:
.send({ embeds:[{embeds: [EmbedBuilder], files: [...] }], .... })
.send({ embeds:[{embeds: [EmbedBuilder], files: [...] }], .... })
Try this, .send({ embeds: embeds[page].embeds
Xu Xiaolan
Xu XiaolanOP•2y ago
alright hmm now its showing the embed but the colour is always red, ill try messing with it a bit more, this is definitely a step forward!
sexy dark chocolate
You understand what I was saying though?
Xu Xiaolan
Xu XiaolanOP•2y ago
yeye, i was just accessing the properties wrong right?
sexy dark chocolate
Yes, also to fox that color thing, change the value you passed to image Embed.setColor in the if(color) statement In your createEncEmbed function, do .setColor(color)
Xu Xiaolan
Xu XiaolanOP•2y ago
ah okay, that makes more sense lol when im setting the value of colour, should it be as a string or does it not matter?
Xu Xiaolan
Xu XiaolanOP•2y ago
like in here
Xu Xiaolan
Xu XiaolanOP•2y ago
i heard javascript is really finnicky with these things
sexy dark chocolate
I mean, the api accepts it as a string but I don't think the embedbuilder would, jus to be safe don't put it in a string
Xu Xiaolan
Xu XiaolanOP•2y ago
its mostly working now, but problem with colours still, and i was told the problem was somewhere around here
Xu Xiaolan
Xu XiaolanOP•2y ago
probably with how im using .includes the if statement always evaluates to being false nvm i just did it another way that seemd to work, im sure i could use .includes but i cant really figure it out lol now just the last thing i have to do, allow the image to also pop up xd oh wait i never declared it... that couldn't have been the problem could it? DumFuckJuice
Xu Xiaolan
Xu XiaolanOP•2y ago
now i just use 2 for loops for it
Xu Xiaolan
Xu XiaolanOP•2y ago
well i'd want it to change sometimes, i wouldnt want it to stay a constant
Xu Xiaolan
Xu XiaolanOP•2y ago
like in these two scenarios, green being the user that card, red being the user does not, ill look into .some though cuz its always good to learn some new code
Xu Xiaolan
Xu XiaolanOP•2y ago
sexy dark chocolate
I said the error is here
sexy dark chocolate
In your if(color), you don't set it to the color
Xu Xiaolan
Xu XiaolanOP•2y ago
yeah i noticed that, it still hadn't worked then, the problem was just with my .includes ah ic, ill look into it if its more efficient then (doubt 2 for loops are more efficient lol) thanks for the help guys ^^
Want results from more Discord servers?
Add your server