#Just tried to log it it didnt give me

1 messages · Page 1 of 1 (latest)

pine glacier
#

So console.log(file) printed undefined?

limber temple
#

not even undefined

#

ill show u the stack

#
C:\Users\tejee_n\Documents\GitHub\new-republic-bot>node index.js
{}
C:\Users\tejee_n\Documents\GitHub\new-republic-bot\index.js:31
    bot.commands.set(file.data.name.toLowerCase(), file)
                               ^

TypeError: Cannot read properties of undefined (reading 'name')
    at Object.<anonymous> (C:\Users\tejee_n\Documents\GitHub\new-republic-bot\index.js:31:32)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47

C:\Users\tejee_n\Documents\GitHub\new-republic-bot>
#

just that

#

it didnt even try to log it

limber mango
#

where did u try to log?

pine glacier
#

can you show the file again so its easier to look at in this thread?

limber mango
#

C:\Users\tejee_n\Documents\GitHub\new-republic-bot>node index.js
{}

#

it logs it right there, no? ^

limber temple
#

oh yeah ur right

#

but that means its not reading any command files

pine glacier
#

yes the empty {}

#

what is your dir look like?

limber temple
#

dir?

pine glacier
#

sorry, directory

limber mango
#

directory structure

limber temple
#

can u elaborate idk what that means

#

which directory

pine glacier
#

ie

src/commands/ping.js
or
src/commands/system/ping.js
limber temple
#

how would i get that directory

limber mango
#

You see it in your file explroer or in your vscode (f.ex)

pine glacier
#

example of mine

limber temple
#

oh

pine glacier
#

For reference (easy to refer to)
i didnt want to scroll back up lol

const commands = readdirSync('./Commands').filter(file => file.endsWith('.js'));





for (const command of commands) {

    const file = require(`./Commands/${command}`)
    bot.commands.set(file.name.toLowerCase(), file)

    if (file.data) {
        bot.slashcommands.push(file.data)
    } 
}

console.log(bot.name.commands)


const events = readdirSync('./Events')

for (const event of events ) {
    const file = require(`./Events/${event}`)
    const name = event.split('.')[0]

    bot.on(name, file.execute.bind(null, bot))
}
limber temple
#

oh ok lol

pine glacier
#

if possible can we see what pvpclose looks like

limber mango
#

wait, did u log file or bot.name.commands in the code above?
ok

limber temple
#

it didnt reach bot.name.commands

limber temple
#

I havent actually started working on the code within it, so its the same as the pvp request

pine glacier
#

Also not sure where u placed the console log but i was talking about here:

const file = require(`./Commands/${command}`)
console.log(file)
bot.commands.set(file.name.toLowerCase(), file)
pine glacier
limber temple
#

that ones easier to read

limber mango
#

did this ever work?

pine glacier
#

and the other one is same exact?

limber temple
#

im not using subcommands anymore

limber temple
#

It did until file just randomly decided to off itself

limber temple
#

that could be partly why

pine glacier
limber temple
#

why would it read the other one first

pine glacier
#

the way its ordered in the file system

limber temple
#

oh ok

pine glacier
#

top down

#

so make sure it has bare minimum required values, functions can be empty

limber temple
#

just double checked

#

they arent exactly the same

pine glacier
#

but needs name and data

limber temple
#

I have a switch case that was working in my other file

pine glacier
#

maybe i thought to far ahead
before
const file = require('./Commands/${command}')
can you log command (console.log(command))

limber temple
#
{
  name: 'pvprequest',
  description: 'PVP Request Command',
  data: SlashCommandBuilder {
    options: [
      [SlashCommandSubcommandBuilder],
      [SlashCommandSubcommandBuilder]
    ],
    name: 'pvprequest',
    name_localizations: undefined,
    description: 'Command to request PVP',
    description_localizations: undefined,
    default_permission: false,
    default_member_permissions: undefined,
    dm_permission: undefined
  },
  slashexecute: [AsyncFunction: slashexecute]
}
pvprequest.js
{
  name: 'pvprequest',
  description: 'PVP Request Command',
  data: SlashCommandBuilder {
    options: [
      [SlashCommandSubcommandBuilder],
      [SlashCommandSubcommandBuilder]
    ],
    name: 'pvprequest',
    name_localizations: undefined,
    description: 'Command to request PVP',
    description_localizations: undefined,
    default_permission: false,
    default_member_permissions: undefined,
    dm_permission: undefined
  },
  slashexecute: [AsyncFunction: slashexecute]
pine glacier
limber temple
#

its in index.js

#

do i need to move that to the top?

pine glacier
#

no

limber temple
#

yep

#

oh well no

#
C:\Users\tejee_n\Documents\GitHub\new-republic-bot\index.js:38
console.log(bot.name.commands)
                     ^

TypeError: Cannot read properties of undefined (reading 'commands')
    at Object.<anonymous> (C:\Users\tejee_n\Documents\GitHub\new-republic-bot\index.js:38:22)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
#

that too

pine glacier
limber temple
#


const { Client, GatewayIntentBits , Partials } = require('discord.js')

const { readdirSync } = require('fs')

const { Token} = require('./config.json')

//const intents = new GatewayIntentBits(['GUILDS', 'GUILD_MEMBERS', 'GUILD_MESSAGES'])

const bot = new Client({ intents: [GatewayIntentBits.Guilds], partials: [Partials.Channel] });

//const bot = new Client({ intents: intents })

bot.commands = new Map()
bot.slashcommands = []




const commands = readdirSync('./Commands').filter(file => file.endsWith('.js'));





for (const command of commands) {
console.log(command)
    const file = require(`./Commands/${command}`)
    console.log(file)
    bot.commands.set(file.data.name.toLowerCase(), file)

    if (file.data) {
        bot.slashcommands.push(file.data)
    } 
}

console.log(bot.name.commands)


const events = readdirSync('./Events')

for (const event of events ) {
    const file = require(`./Events/${event}`)
    const name = event.split('.')[0]

    bot.on(name, file.execute.bind(null, bot))
}

bot.login(Token)
#

oh wait it was just console.log bot.name.commands

#

that was now giiving an error, i can just remove that since console.log(command) returns the same thing

pine glacier
#

yea remove console.log(bot.name.commands)

limber temple
#

that seems to have worked, now its just telling me the names need to be different

#

Thanks for your help

pine glacier
#
for (const command of commands) {
console.log(command)

this part should be printing both files

limber temple
#

ye

pine glacier
limber temple
#

Yeah i should be fine from here

#

@limber mango Thanks for your help aswell

pine glacier
#

how did i miss that console log damn