Setting buffer attachment not working. The resource must be a string, Buffer or a valid file stream

Hi, I am getting the error The resource must be a string, Buffer or a valid file stream. when trying to send file attachments from buffers. Why might this be happening? For sending the message:
await this.getShardUtil(client).broadcastEval(
async (client: any, context: { embeds: any[], attachments: any[], permissions: Record<string, any> }) => {
// bla bla bla
if (logsChannel && logsChannel.isTextBased()) {
await logsChannel.send({ embeds: context.embeds, files: context.attachments });
}
}
}, { context: { embeds: [ embed ], attachments: [ ...attachments ], permissions: { ViewChannel: PermissionFlagsBits.ViewChannel.toString() } } });
await this.getShardUtil(client).broadcastEval(
async (client: any, context: { embeds: any[], attachments: any[], permissions: Record<string, any> }) => {
// bla bla bla
if (logsChannel && logsChannel.isTextBased()) {
await logsChannel.send({ embeds: context.embeds, files: context.attachments });
}
}
}, { context: { embeds: [ embed ], attachments: [ ...attachments ], permissions: { ViewChannel: PermissionFlagsBits.ViewChannel.toString() } } });
For turning the base64 string to a buffer:

if (key === "icon" || key === "banner") {
const imageBuffer: Buffer = Buffer.from(reportedServer[key].split(",")[1], "base64");
const imageType: string = reportedServer[key].split(";")[0].split("/")[1];

const attachment = new AttachmentBuilder(imageBuffer, { name: `${key}.${imageType}`, });
attachments.push(attachment);

return `> **${formattedKey}:** [${key}.${imageType}](attachment://${key}.${imageType})`;
}

if (key === "icon" || key === "banner") {
const imageBuffer: Buffer = Buffer.from(reportedServer[key].split(",")[1], "base64");
const imageType: string = reportedServer[key].split(";")[0].split("/")[1];

const attachment = new AttachmentBuilder(imageBuffer, { name: `${key}.${imageType}`, });
attachments.push(attachment);

return `> **${formattedKey}:** [${key}.${imageType}](attachment://${key}.${imageType})`;
}
No description
2 Replies
d.js toolkit
d.js toolkit3d 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 OP
Swyftey
SwyfteyOP2d ago
so, it has to do with the way I am passing the attachments through the context. not sure how to fix fixed

Did you find this page helpful?