Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

268
Views
TypeError: (intermediate value) is not a function

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.

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

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(/*...*/)
about 4 years ago · Santiago Gelvez Report

0

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)=>{
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!