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);
}
}
}