Change forEach loop to filter

This commit is contained in:
SileNce5k 2022-04-10 21:51:44 +02:00
parent 4e41a035ed
commit 4adc97d6ae
No known key found for this signature in database
GPG key ID: C507260E7F2583AD

View file

@ -1,15 +1,10 @@
const fs = require('fs');
module.exports = function(customName){
let author = false;
const customPath = './data/customCommands.json';
let json = fs.readFileSync(customPath, 'utf8');
let customCommands = JSON.parse(json)
customCommands.forEach(function (customCommand) {
if (customCommand.customName === customName) {
author = customCommand.author;
}
});
return author;
let author = customCommands.filter(customCommands => customCommands.customName === customName);
if(author.length === 0) return false;
return author[0].author;
}