App didnt respond

async function handlePtMake(interaction) {
try {
const attachment = interaction.options.getAttachment('file');

if (!attachment || !attachment.name.endsWith('.xlsx')) {
await interaction.reply({ content: 'Please upload a valid Excel file.', ephemeral: true });
return;
}

await interaction.deferReply({ ephemeral: true });

// Fetch the attachment
const response = await fetch(attachment.url);
if (!response.ok) {
throw new Error('Failed to download the Excel file.');
}


async function handlePtMake(interaction) {
try {
const attachment = interaction.options.getAttachment('file');

if (!attachment || !attachment.name.endsWith('.xlsx')) {
await interaction.reply({ content: 'Please upload a valid Excel file.', ephemeral: true });
return;
}

await interaction.deferReply({ ephemeral: true });

// Fetch the attachment
const response = await fetch(attachment.url);
if (!response.ok) {
throw new Error('Failed to download the Excel file.');
}


2 Replies
d.js toolkit
d.js toolkit3mo 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
Thind
ThindOP3mo ago
const buffer = await response.buffer();

// Read the Excel file
const workbook = xlsx.read(buffer, { type: 'buffer' });
const sheet = workbook.Sheets[workbook.SheetNames[0]];
const data = xlsx.utils.sheet_to_json(sheet);

// Create a canvas and draw the data
const canvas = createCanvas(800, 600);
const ctx = canvas.getContext('2d');

ctx.fillStyle = '#fff';
ctx.fillRect(0, 0, canvas.width, canvas.height);

ctx.fillStyle = '#000';
ctx.font = '16px Arial';
ctx.fillText('Team', 50, 50);
ctx.fillText('Chickens', 150, 50);
ctx.fillText('Position Points', 250, 50);
ctx.fillText('Finish Points', 400, 50);
ctx.fillText('Total Points', 550, 50);

data.slice(0, 26).forEach((row, index) => {
const y = 80 + index * 30;
ctx.fillText(row.Team || '', 50, y);
ctx.fillText(row.Chickens?.toString() || '0', 150, y);
ctx.fillText(row['Position Points']?.toString() || '0', 250, y);
ctx.fillText(row['Finish Points']?.toString() || '0', 400, y);
ctx.fillText(row['Total Points']?.toString() || '0', 550, y);
});

const bufferImage = canvas.toBuffer();

// Respond with the generated image
await interaction.editReply({
content: 'Here is your point table image.',
files: [{ attachment: bufferImage, name: 'PointTable.png' }],
});

} catch (error) {
console.error('Error in pt_make command:', error);
try {
await interaction.editReply({ content: 'There was an error processing your request. Please try again later.', ephemeral: true });
} catch (editError) {
console.error('Failed to edit reply:', editError);
}
}
}
const buffer = await response.buffer();

// Read the Excel file
const workbook = xlsx.read(buffer, { type: 'buffer' });
const sheet = workbook.Sheets[workbook.SheetNames[0]];
const data = xlsx.utils.sheet_to_json(sheet);

// Create a canvas and draw the data
const canvas = createCanvas(800, 600);
const ctx = canvas.getContext('2d');

ctx.fillStyle = '#fff';
ctx.fillRect(0, 0, canvas.width, canvas.height);

ctx.fillStyle = '#000';
ctx.font = '16px Arial';
ctx.fillText('Team', 50, 50);
ctx.fillText('Chickens', 150, 50);
ctx.fillText('Position Points', 250, 50);
ctx.fillText('Finish Points', 400, 50);
ctx.fillText('Total Points', 550, 50);

data.slice(0, 26).forEach((row, index) => {
const y = 80 + index * 30;
ctx.fillText(row.Team || '', 50, y);
ctx.fillText(row.Chickens?.toString() || '0', 150, y);
ctx.fillText(row['Position Points']?.toString() || '0', 250, y);
ctx.fillText(row['Finish Points']?.toString() || '0', 400, y);
ctx.fillText(row['Total Points']?.toString() || '0', 550, y);
});

const bufferImage = canvas.toBuffer();

// Respond with the generated image
await interaction.editReply({
content: 'Here is your point table image.',
files: [{ attachment: bufferImage, name: 'PointTable.png' }],
});

} catch (error) {
console.error('Error in pt_make command:', error);
try {
await interaction.editReply({ content: 'There was an error processing your request. Please try again later.', ephemeral: true });
} catch (editError) {
console.error('Failed to edit reply:', editError);
}
}
}
1st part 2nd node version : 20.17.0 discord.js version : 14.16.2
Want results from more Discord servers?
Add your server