-4

how can i solve my error in line 16 witch is syntax error can any one help me to fix it this is 'command handler' for discord js

const { Events } = require("../Validation/Events");
const { promisify } = require("util");
const { glob } = require("glob");
const PG = promisify(glob);
const Ascii = require("ascii-table");

module.exports = async (client) => {
    const Table = new Ascii("Events Loaded");

    (await PG(`${process.cwd()}/Events/*/*.js`)).map(async (file) => {
        const event = require(file);

        if (event.name) {
            if(!Events.includes(event.name))
            const L = file.split("/");
            return Table.addRow(`${event.name || "MISSING"}`, `⛔ Event name is either invalid or missing ${L[6] + `/` + L[7]}`);
        }

        if(event.once)
        client.once(event.name, (...args) => event.execute(...args, client));
        else
        client.on(event.name, (...args) => event.execute(...args, client));
        
        await Table.addRow(event.name, "✔️ SUCCESSFUL")
    });
    
    console.log(Table.toString());
}```
V E X
  • 45
  • 9
  • [Is it a bad practice to use an if-statement without curly braces?](https://stackoverflow.com/questions/2125066/is-it-a-bad-practice-to-use-an-if-statement-without-curly-braces) – Ivar Feb 19 '22 at 19:51

2 Answers2

0

What is

if(!Events.includes(event.name))
const L = file.split("/");
return Table.addRow(`${event.name || "MISSING"}`, `⛔ Event name is either invalid or missing ${L[6] + `/` + L[7]}`);

supposed to do ?

You most likely wanted to group those

if(!Events.includes(event.name)) {
    const L = file.split("/");
    return Table.addRow(`${event.name || "MISSING"}`, `⛔ Event name is either invalid or missing ${L[6] + `/` + L[7]}`);
}
Gabriele Petrioli
  • 191,379
  • 34
  • 261
  • 317
0

You are saying

if(!Events.includes(event.name))
const L = file.split("/");

Which doesn't make sense because const is block scoped. You forgot {}

if (event.name) {
   if(!Events.includes(event.name)) {
       const L = file.split("/");
       return Table.addRow(`${event.name || "MISSING"}`, `⛔ Event name is either invalid or missing ${L[6] + `/` + L[7]}`);
    }
}
digitalniweb
  • 838
  • 1
  • 7
  • 15