Attachment not being sent

I have been trying to send a attachment of some backup data in one of the channels, however every time it sends the message content but the backup attachment is never there, no error as well that it couldn't send the attachment or something
9 Replies
d.js toolkit
d.js toolkit5mo 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
Void
Void5mo ago
async function backupAndSend(serverId, tier) {
try {
const serverData = await Server.findOne({ serverId: serverId, originalGrinderTier: tier });

if (!serverData) {
console.error(`Server with ID ${serverId} and tier ${tier} not found.`);
return;
}

const backupData = {
serverId: serverData.serverId,
[tier]: {
users: serverData.users,
retiredUsers: serverData.retiredUsers,
},
};

const backupJSON = JSON.stringify(backupData, null, 2);
const channelId = '1182082163542335488';

const channel = await client.channels.fetch(channelId);
const buffer = Buffer.from(backupJSON, 'utf-8');
const attachment = new AttachmentBuilder(buffer, `backup_${tier}.json`);

await channel.send(`Daily Backup Data for Server ${serverId} - ${tier}:`, { files: [attachment] });

console.log(`Backup and send for Server ${serverId} - ${tier} successful.`);
} catch (error) {
console.error(`Error during backup and send for Server ${serverId} - ${tier}:`, error);
}
}
async function backupAndSend(serverId, tier) {
try {
const serverData = await Server.findOne({ serverId: serverId, originalGrinderTier: tier });

if (!serverData) {
console.error(`Server with ID ${serverId} and tier ${tier} not found.`);
return;
}

const backupData = {
serverId: serverData.serverId,
[tier]: {
users: serverData.users,
retiredUsers: serverData.retiredUsers,
},
};

const backupJSON = JSON.stringify(backupData, null, 2);
const channelId = '1182082163542335488';

const channel = await client.channels.fetch(channelId);
const buffer = Buffer.from(backupJSON, 'utf-8');
const attachment = new AttachmentBuilder(buffer, `backup_${tier}.json`);

await channel.send(`Daily Backup Data for Server ${serverId} - ${tier}:`, { files: [attachment] });

console.log(`Backup and send for Server ${serverId} - ${tier} successful.`);
} catch (error) {
console.error(`Error during backup and send for Server ${serverId} - ${tier}:`, error);
}
}
treble/luna
treble/luna5mo ago
.send takes a single object And you dont need to fetch the channel, they're cached by the Guilds intent
d.js docs
d.js docs5mo ago
:interface: MessageCreateOptions The options for sending a message.
treble/luna
treble/luna5mo ago
and attachment builder takes an object as second param
Void
Void5mo ago
Trying it like this now
const attachment = new AttachmentBuilder({ buffer: Buffer.from(backupJSON), name: `backup_${tier}.json` });


await channel.send({
content: `Daily Backup Data for Server ${serverId} - ${tier}:`,
files: [{
name: `backup_${tier}.json`,
content: [attachment],
}],
});
const attachment = new AttachmentBuilder({ buffer: Buffer.from(backupJSON), name: `backup_${tier}.json` });


await channel.send({
content: `Daily Backup Data for Server ${serverId} - ${tier}:`,
files: [{
name: `backup_${tier}.json`,
content: [attachment],
}],
});
And it's finally giving some TypeError of undefined Symbol.asyncIterator What is wrong?
d.js docs
d.js docs5mo ago
:class: AttachmentBuilder Represents an attachment builder
treble/luna
treble/luna5mo ago
please read the docs, dont just guess
Void
Void5mo ago
I thought your explanation was not enough and was confused, but after reading it seriously and trying a few times it worked Thanks a lot :Dance_TJN: