#Error

1 messages ยท Page 1 of 1 (latest)

lilac turtle
#

I did it and try running the code but got this error

#
C:\Users\great\OneDrive\Desktop\Angelus-Slash\Handlers\Commands.js:46
        Client.application.commands.set(CommandsArray).then(async (command) => {
                           ^

TypeError: Cannot read properties of undefined (reading 'commands')
    at Client.<anonymous> (C:\Users\great\OneDrive\Desktop\Angelus-Slash\Handlers\Commands.js:46:28)
    at Client.emit (node:events:402:35)
    at WebSocketManager.triggerClientReady (C:\Users\great\OneDrive\Desktop\Angelus-Slash\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:17)
    at WebSocketManager.checkShardsReady (C:\Users\great\OneDrive\Desktop\Angelus-Slash\node_modules\discord.js\src\client\websocket\WebSocketManager.js:367:10)
    at WebSocketShard.<anonymous> (C:\Users\great\OneDrive\Desktop\Angelus-Slash\node_modules\discord.js\src\client\websocket\WebSocketManager.js:189:14)
    at WebSocketShard.emit (node:events:390:28)
    at WebSocketShard.checkReady (C:\Users\great\OneDrive\Desktop\Angelus-Slash\node_modules\discord.js\src\client\websocket\WebSocketShard.js:475:12)
    at WebSocketShard.onPacket (C:\Users\great\OneDrive\Desktop\Angelus-Slash\node_modules\discord.js\src\client\websocket\WebSocketShard.js:447:16)
    at WebSocketShard.onMessage (C:\Users\great\OneDrive\Desktop\Angelus-Slash\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
    at WebSocket.onMessage (C:\Users\great\OneDrive\Desktop\Angelus-Slash\node_modules\ws\lib\event-target.js:199:18)
    at WebSocket.emit (node:events:390:28)
    at Receiver.receiverOnMessage (C:\Users\great\OneDrive\Desktop\Angelus-Slash\node_modules\ws\lib\websocket.js:1137:20)
    at Receiver.emit (node:events:390:28)
    at Receiver.dataMessage (C:\Users\great\OneDrive\Desktop\Angelus-Slash\node_modules\ws\lib\receiver.js:528:14)
    at Receiver.getData (C:\Users\great\OneDrive\Desktop\Angelus-Slash\node_modules\ws\lib\receiver.js:446:17)
    at Receiver.startLoop (C:\Users\great\OneDrive\Desktop\Angelus-Slash\node_modules\ws\lib\receiver.js:148:22)
wooden cipher
#

did you define client?

lilac turtle
#

You mean clientID?

wooden cipher
#

nono

#

what type is client

lilac turtle
#

Uhm

#
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('Commands 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.context && !command.description)
        return Table.addRow(file.split("/"), "๐Ÿ”ธ FAILED", "Missing a Description")
    
        if (command.permission) {
            if(Perms.includes(command.permission))
            command.defaultPermission = false;
            else
            return Table.addRow(file.split("/"), "๐Ÿ”ธ FAILED", "Permission is Invalid")
        }

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

        await Table.addRow(command.name, "โœ… SUCCESSFULL");

    });

    console.log(Table.toString());

    //Permissions Check

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

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

                return Client.application.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 Client.application.commands.permissions.set({ fullPermissions });
        })
    })
}
lilac turtle
wooden cipher
#

oh, it should be lowercase client

#

client.application

lilac turtle
#

Ahh

#
C:\Users\great\OneDrive\Desktop\Angelus-Slash\Handlers\Commands.js:51
                return client.application.roles.cache.filter((r) => r.permissions.has(cmdPerms));
                                                ^

TypeError: Cannot read properties of undefined (reading 'cache')
    at Roles (C:\Users\great\OneDrive\Desktop\Angelus-Slash\Handlers\Commands.js:51:49)
    at C:\Users\great\OneDrive\Desktop\Angelus-Slash\Handlers\Commands.js:55:31
    at Map.reduce (C:\Users\great\OneDrive\Desktop\Angelus-Slash\node_modules\@discordjs\collection\dist\index.js:1:3544)
    at C:\Users\great\OneDrive\Desktop\Angelus-Slash\Handlers\Commands.js:54:45
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
wooden cipher
#

nono

#

just do

#

client.roles

#

application refers to your OAuth app

lilac turtle
#

So remove application?

wooden cipher
#

not to your bot

lilac turtle
#

Ohh

#
C:\Users\great\OneDrive\Desktop\Angelus-Slash\Handlers\Commands.js:46
        client.commands.set(CommandsArray).then(async (command) => {
                                           ^

TypeError: client.commands.set(...).then is not a function
    at Client.<anonymous> (C:\Users\great\OneDrive\Desktop\Angelus-Slash\Handlers\Commands.js:46:44)
    at Client.emit (node:events:402:35)
    at WebSocketManager.triggerClientReady (C:\Users\great\OneDrive\Desktop\Angelus-Slash\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:17)
    at WebSocketManager.checkShardsReady (C:\Users\great\OneDrive\Desktop\Angelus-Slash\node_modules\discord.js\src\client\websocket\WebSocketManager.js:367:10)
    at WebSocketShard.<anonymous> (C:\Users\great\OneDrive\Desktop\Angelus-Slash\node_modules\discord.js\src\client\websocket\WebSocketManager.js:189:14)
    at WebSocketShard.emit (node:events:390:28)
    at WebSocketShard.checkReady (C:\Users\great\OneDrive\Desktop\Angelus-Slash\node_modules\discord.js\src\client\websocket\WebSocketShard.js:475:12)
    at WebSocketShard.onPacket (C:\Users\great\OneDrive\Desktop\Angelus-Slash\node_modules\discord.js\src\client\websocket\WebSocketShard.js:447:16)
    at WebSocketShard.onMessage (C:\Users\great\OneDrive\Desktop\Angelus-Slash\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
    at WebSocket.onMessage (C:\Users\great\OneDrive\Desktop\Angelus-Slash\node_modules\ws\lib\event-target.js:199:18)
    at WebSocket.emit (node:events:390:28)
    at Receiver.receiverOnMessage (C:\Users\great\OneDrive\Desktop\Angelus-Slash\node_modules\ws\lib\websocket.js:1137:20)
    at Receiver.emit (node:events:390:28)
    at Receiver.dataMessage (C:\Users\great\OneDrive\Desktop\Angelus-Slash\node_modules\ws\lib\receiver.js:528:14)
    at Receiver.getData (C:\Users\great\OneDrive\Desktop\Angelus-Slash\node_modules\ws\lib\receiver.js:446:17)
    at Receiver.startLoop (C:\Users\great\OneDrive\Desktop\Angelus-Slash\node_modules\ws\lib\receiver.js:148:22)
wooden cipher
#

huh

#

odd

#

wait

#

nono keep the client.application in that portion

#

as i said

#

application refers to your OAuth application - you want to set your slash commands to the oauth app

lilac turtle
#

Like this

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

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

                return client.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 client.commands.permissions.set({ fullPermissions });
        })
    })
#

@wooden cipher?

wooden cipher
#

replace the

#

client.commands.permissions.set({ fullPermissions });

#

with client.application.commands.permissions.set({ fullPermissions });

lilac turtle
#

Done

#

@wooden cipher

wooden cipher
#

apparently roles doesn't exist on client

#

that's odd

tawny siren
#

Uh

#

Roles are off of a GuildMember object

#

Client is a user

#

...I think so...

#

Well

#

Client isn't a user

#

But client does NOT have a roles property