Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Discord embed picture

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!",
                    });
                }
            }
        }
    );
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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!",
                    });
                }
            }
        }
    );
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading