so I'm currently making a Discord bot using Discord.JS V13.
I keep getting this error when I run the node index.js command
TypeError: (intermediate value) is not a function
at module.exports (C:\Users\myUser\OneDrive\Desktop\Green Hosting Discord bot\Handlers\Events.js:10:5)
I don't know why it is doing this. The code is:
const { Events } = require("../Validation/EventNames");
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(!Events.includes(event.name) || !event.name) {
const L = file.split("/");
await Table.addRow(`${event.name || "MISSING"}`, `⛔ Event name is either invalid or missing: ${L[6] + "/" + L[7]}`)
return;
};
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());
};
If you could help me, that would be amazing. Thank you.
There is no semicolon after const Table = new Ascii("Events Loaded"). The automatic semicolon insertion will only apply if without the semicolon the code would be invalid if concatenated. However here it the code is valid (but fails at runtime):
const Table = new Ascii("Events Loaded")
(await PG(`${process.cwd()}/Events/*/*.js`)).map(/*...*/)
⬇
const Table = new Ascii("Events Loaded")(await PG(`${process.cwd()}/Events/*/*.js`)).map(/*...*/)
As you can see, this would be a function call on the return value of new Ascii("Events Loaded"). However, that isn't a function and can't be called, hence the error.
The solution is therefore to add the missing semicolon here:
const Table = new Ascii("Events Loaded");
// ^
Or, if you want to write code without semicolons, you instead need to insert a semicolon at the start of lines if they begin with certain characters including (, as is the case here:
;(await PG(`${process.cwd()}/Events/*/*.js`)).map(/*...*/)
Try:
const promise = await PG(`${process.cwd()}/Events/*/*.js`)
promise.map(async (file)=>{
// code...
});
Or maybe, It's the semi colomn:
const Table = new Ascii("Events Loaded");
//--------------------------------------^
(await PG(`${process.cwd()}/Events/*/*.js`)).map(async (file)=>{