Myna
DIAdiscord.js - Imagine an app
•Created by Myna on 8/19/2023 in #djs-questions
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;
6 replies