const { getUserXP } = require("../../models/user"); const generateLevelCard = require("../../functions/level/generate_level_card"); const fs = require('fs').promises; const path = require('path'); const os = require('os'); module.exports = { config: { name: "level", usage: true, cooldown: 5000, available: true, permissions: [], roles: [], dm: false, aliases: ['lvl'] }, run: async (client, message, args, db) => { try { const user = await getUserXP(message.author.id); const levelCardBuffer = await generateLevelCard(user); // Create a temporary file path const tempFilePath = path.join(os.tmpdir(), `level_card_${message.author.id}.png`); // Save the buffer to the temporary file await fs.writeFile(tempFilePath, levelCardBuffer); // Upload the file const attachment = await client.Uploader.uploadFile(tempFilePath, "level_card.png"); // Send the message with the attachment await message.channel.sendMessage({ attachments: [attachment] }); // Clean up the temporary file await fs.unlink(tempFilePath).catch(console.error); } catch (error) { console.error('Error in level command:', error); await message.channel.sendMessage({ content: "❌ An error occurred while generating your level card. Please try again later." }); } }, };