Resend Messages in Another Chat

Hey! I'm having a problem downloading and uploading videos. This is code that saves an attachment in a buffer and sends it in a chat. But if I try that way, the video keeps loading infinitely. This works with images correctly. I've tried sending the Attachment object instead of a BufferResolvable, but if I delete the original message, the one sent is broken. Where am I making mistakes?
const currentMessage = currentLot[i];
var attachments = [];

// Loop of attachments
for (const att of currentMessage.attachments) {
try {
if (!att[1].contentType) {
Log.PrintErr(
"Arquivo corrompido!",
new Error()
);
continue;
}

const response = await axios.get(att[1].url, {
responseType: "arraybuffer",
});
const buffer = Buffer.from(response.data);

attachments.push(buffer);
} catch (err) {
return Err({
message: "Ocorreu um erro ao baixar o arquivo!",
type: "external",
obj: err,
});
}
}

try {
await params.essentialData.destinationChat.send({
content: `Mensagem ${currMessNumb}!`,
files: attachments,
});
} catch (err) {
return Err({
message: "Ocorreu um erro ao enviar a mensagem!",
type: "external",
obj: err,
});
}

currMessNumb += 1;
const currentMessage = currentLot[i];
var attachments = [];

// Loop of attachments
for (const att of currentMessage.attachments) {
try {
if (!att[1].contentType) {
Log.PrintErr(
"Arquivo corrompido!",
new Error()
);
continue;
}

const response = await axios.get(att[1].url, {
responseType: "arraybuffer",
});
const buffer = Buffer.from(response.data);

attachments.push(buffer);
} catch (err) {
return Err({
message: "Ocorreu um erro ao baixar o arquivo!",
type: "external",
obj: err,
});
}
}

try {
await params.essentialData.destinationChat.send({
content: `Mensagem ${currMessNumb}!`,
files: attachments,
});
} catch (err) {
return Err({
message: "Ocorreu um erro ao enviar a mensagem!",
type: "external",
obj: err,
});
}

currMessNumb += 1;
2 Replies
d.js toolkit
d.js toolkit•10mo 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!
Myna
Myna•10mo ago
Ok... Regarding the file size, I already checked. They are all under 1mb. My concern is: using just the link, will in the end be two independent files in two independent uploads? If the second message is interfered with by deleting the first one, that would be a big problem 😭 Oh, and thanks for the reply <3 Okay, I understand now Thanks!!