I tried making an evaluate command with discordjs and im trying to log the code in a file.
This is my code rn:
const { Client, MessageEmbed, MessageAttachment } = require('discord.js');
const axios = require('axios');
const fs = require('fs');
const { inspect } = require('util');
module.exports = {
name : "evaluate",
aliases : ['eval'],
description: "This command allows the developer to execute a code!",
run : async (client, messageCreate, args) => {
if(messageCreate.author.id !== '754165961946562601') return;
try {
const code = args.join(" ");
if (!code) {
return messageCreate.channel.send("Please Provide A code to eval!");
}
let evaled = await eval(code);
if (typeof evaled !== "string")
evaled = require("util").inspect(evaled);
const output = await evaled.substring(0,1000)
const input = await code.substring(0,1000)
let embed = new MessageEmbed()
.setAuthor("Eval", messageCreate.author.avatarURL())
.addField("Input", `\`\`\`${input}\`\`\``)
.addField("Output", `\`\`\`${output}\`\`\``)
.setColor("GREEN");
messageCreate.channel.send({ embeds: [embed] })
.then(msg => {
setTimeout( () => {
msg.delete()
}, 10000
)
});
} catch (err) {
messageCreate.channel.send(`\`ERROR\` \`\`\`js\n${err}\n\`\`\``);
}
const data = await axios.get('http://worldtimeapi.org/api/timezone/Asia/Kolkata')
fs.writeFileSync(`./eval-logs/eval-${data.data.datetime}.txt`, "exodus")
}
}
Everything works, but it returns the error that the file is not found. Now I want it to create a file named eval-${data.data.datetime}.txt
in eval-logs command. Can i even do it?