Setting buffer attachment not working. The resource must be a string, Buffer or a valid file stream
Hi,
I am getting the error
Why might this be happening?
For sending the message:
For turning the base64 string to a buffer:
I am getting the error
The resource must be a string, Buffer or a valid file stream.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})`;
}
