File Attachment

How do I attach my attachment in the embed after rank.build(), given that this embed is needed for my my-karma.js command? I mean when my command is called, it calls an embed from another file where everything is very connected.
my-karma.js:
const { SlashCommandBuilder } = require("discord.js");
const { getMemberTotalKarma } = require("../../modules/member");

module.exports = {
  data: new SlashCommandBuilder().setName("my-karma").setDescription("meow"),
  async execute(interaction) {
    await interaction.deferReply({
      fetchReply: true,
      deferReply: true,
    })

    const embed = await getMemberTotalKarma(interaction.member);

    await interaction.editReply({
      embeds: [embed]
    })
  }
}

src/modules/member/controller.js:
...
const getMemberTotalKarma = async (memberDiscordId, interaction) => {
  try {
...
    if (gradationValue && gradationRole) {
      await interaction.deferReply({
        fetchReply: true,
        deferReply: true,
      })
      ...
      const rank = new canvacord.Rank()
        .setAvatar(img)
        .setCurrentXP(karma)
        .setRequiredXP(karmaNeededForNextRole)
        .setProgressBar("#e523ff")
        .setUsername(memberDiscordId.user.username)
        .renderEmojis(true)
        .setRank(karma, "kR", true)

      rank.build()
      .then(async buffer => {
        const attachment = new AttachmentBuilder(buffer, { name: 'rank.png' })
        return new EmbedBuilder()
        .setColor(colors.primary)
        .setDescription(`meow`)
        .setImage(`attachment://${attachment.name}`);
      });
    }
    return new EmbedBuilder().setColor(colors.primary).setDescription(`meow2`);
  } catch (error) {
    console.log(error);
    return new EmbedBuilder().setColor(colors.danger).setDescription(`error`);
  }
}
...
Was this page helpful?