'How TypeError: (intermediate value) is not a function can be solved please

My code :

    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"}`, `⛔ Events name est invalide ou absent : ${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());


}

It's for my Event handler file but there is an error:

await PG(${process.cwd()}/Events/*/*.js)).map(async (file) => { ^

TypeError: (intermediate value) is not a function

Can you help me please



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source