First time asking a question. Have gone through similar questions but does not seem to match my inquiry.
Trying to create a calendar with discord bot and getting the favorable "Cannot send an empty message." The bot is able to read the commands and using fs.readFileSync on the specific file returns favorable results.
However, I am trying to use fs.readdir to get the list of files first and then iterate through them with a for loop. The console.log shows favorable results but the bot shows DiscordAPIError: Cannot send an empty message.
readFS.js file
var fs = require("fs");
function readPath(){
fs.readdir('./calendar/', function(err, list){
if(err) throw err;
for(let i=0; i<list.length; i++){
return readFile('./calendar/'+list[i]);
//return list[i];
}
})
}
function readFile(file, err){
if(err) return err;
console.log(JSON.parse(fs.readFileSync(file)))
return JSON.stringify(JSON.parse(fs.readFileSync(file)));
}
process.on('unhandledRejection', (reason, promise) => {
console.log('Unhandled Rejection at:', reason.stack || reason)
})
module.exports = {
readFile,
readPath
}
I would like to stay away from promises if possible as they have been kind of hard for me to completely understand. The discord bot is able to discern my arguments with no issue.
bot.js file
else if(arguments.length > 0 && arguments[0] == "view" && arguments[1] == 'list'){
receivedMessage.channel.send("Retreiving Calendar!")
receivedMessage.channel.send(read.readPath())
//console.log(read.readPath())
}
Actual Error in console:
Command received: calendar
Arguments: view,list
{ Title: 'Test Event',
Description: 'Event for testing the output of JSON',
StartDate: 'Today',
StartTime: '3 hours from now',
LockedTo: 'Guild Only' }
Unhandled Rejection at: DiscordAPIError: Cannot send an empty message
at item.request.gen.end (C:\Users\afrederick\Documents\GitHub\xtreamexe\node_modules\discord.js\src\client\rest\RequestHandlers\Sequential.js:85:15)
at then (C:\Users\afrederick\Documents\GitHub\xtreamexe\node_modules\snekfetch\src\index.js:215:21)
at process._tickCallback (internal/process/next_tick.js:68:7)
Hopefully I put enough information.