Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

285
Vistas
TypeError: [] is not a function

I am making a Discord bot command handler, and I keep getting this error:

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

TypeError: [] is not a function

Here is my code:

const { Perms } = require('../Validation/Permissions');
const { Client } = require('discord.js')
const { promisify } = require("util")
const { glob } = require('glob');
const PG = promisify(glob)
const Ascii = require('ascii-table')

/** 
 * @param {Client} client
*/

module.exports = async (client) => {
    const Table = new Ascii('Command Loaded')

    CommandsArray = []

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

        if (!command.name)
        return Table.addRow(file.split("/")[7], 'FAILED', 'Missing a name.')

        if (!command.description)
        return Table.addRow(command.name, 'FAILED', 'Missing the description.')

        if (command.permission) {
            if (Perms.includes(command.permission))
            command.defaultPermission = false;
            else
            return Table.addRow(command.name,'FAILED','Permission is invalid')
        }

        client.commands.set(command.name, command);
        CommandsArray.push(command);

        await Table.addRow(command.name, 'SUCCESSFUL');
    })

    console.log(Table.toString())

    // Permissions check //

    client.on('ready', async() => {
        const MainGuild = await client.guilds.cache.get('940180806696058910');

        MainGuild.commands.set(CommandsArray).then(async (command) => {
            const Roles = (commandName) => {
                const cmdPerms = CommandsArray.find((c) => c.name === commandName).permission
                if (!cmdPerms) return null;

                return MainGuild.roles.cache.filter((r) => r.permissions.has(cmdPerms))
            }

            const fullPermissions = command.reduce((accumulator, r) => {
                const roles = Roles(r.name);
                if (!roles) return accumulator;

                const permissions = roles.reduce((a, r) => {
                    return [...a,{id: r.id, type: 'ROLE', permission: true}]
                }, [])

                return [...accumulator, {id: r.id, permissions}]
            }, [])

            await MainGuild.commands.permissions.set({ fullPermissions });

        })

    })
}

I've done some googling, but I was unable to find anything related to just [], type error usually appears when there is a spelling mistake in your code. I have gone through my code numerous times and have been completely unable to find any mistakes, I just cannot figure this out. I would really appreciate some help, thank you!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Please use semi-colons!

Add ; onto the line above the PG where you define an empty array, JS sees the array and also brackets right after and this thinks you are executing a function because JS when compiled does not look at lines or spacing.

CommandsArray = [];

(await PG(`${process.cwd()}/Commands/*/*js`)).map(async (file) => {
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda