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]
})
}
}
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`);
}
}
...
...
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`);
}
}
...
2 Replies
d.js toolkit
d.js toolkit13mo 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! - Marked as resolved by staff
Syjalo
Syjalo13mo ago
Return both the attachment and embed. Btw it's better to make the getMemberTotalKarma function return only the attachment, build the embed and add the attachment ot it in the command file.
Want results from more Discord servers?
Add your server