I have a problem with my discord bot. I want that the picture is being displayed in the embed if that is possible. Currently the image is like bing posted as a own message outside of the embed.
This is my code, could maybe someone help me to figure this out?
function fight(interaction, pool, swords) {
const id = interaction.member.user.id;
const random_sword = swords[Math.floor(Math.random() * swords.length)];
const sword_name = random_sword.name;
const sword_database = random_sword.database;
const file = new AttachmentBuilder("/home/user/win.jpg");
pool.query(
"UPDATE `inv` SET ?? = ?? + 1, `fight` = NOW() WHERE `id` = ? AND (`fight` < DATE_SUB(NOW(), INTERVAL 4 HOUR) or `fight` is null);",
[sword_database, sword_database, id],
(err, result) => {
if (err) {
console.log(err);
return interaction.reply({
content: "Database error!",
ephemeral: true,
});
} else {
if (!(result.changedRows === 0)) {
const embed = new EmbedBuilder()
.setTitle("Win!")
.setDescription(`Congrats you won!\nYou grabbed a ${sword_name}!`)
.setColor("#00ff00")
.setAuthor({
name: interaction.member.user.username,
iconURL: interaction.member.user.avatarURL(),
})
.setTimestamp();
return interaction.reply({
embeds: ,
files: [file],
});
} else {
return interaction.reply({
content: "You already fought in the last 4 hours!",
});
}
}
}
);
}
>Solution :
To showcase the image in the embed, you must specify the attachment path and assign it to the Image attribute within the embed.
I marked the changed rows with //new
function fight(interaction, pool, swords) {
const id = interaction.member.user.id;
const random_sword = swords[Math.floor(Math.random() * swords.length)];
const sword_name = random_sword.name;
const sword_database = random_sword.database;
const file = new AttachmentBuilder("/home/user/win.jpg");
const path = "attachment://win.jpg"; //new
pool.query(
"UPDATE `inv` SET ?? = ?? + 1, `fight` = NOW() WHERE `id` = ? AND (`fight` < DATE_SUB(NOW(), INTERVAL 4 HOUR) or `fight` is null);",
[sword_database, sword_database, id],
(err, result) => {
if (err) {
console.log(err);
return interaction.reply({
content: "Database error!",
ephemeral: true,
});
} else {
if (!(result.changedRows === 0)) {
const embed = new EmbedBuilder()
.setTitle("Win!")
.setDescription(`Congrats you won!\nYou grabbed a ${sword_name}!`)
.setColor("#00ff00")
.setImage(path) //new
.setAuthor({
name: interaction.member.user.username,
iconURL: interaction.member.user.avatarURL(),
})
.setTimestamp();
return interaction.reply({
embeds: ,
files: [file],
});
} else {
return interaction.reply({
content: "You already fought in the last 4 hours!",
});
}
}
}
);
}