#Just tried to log it it didnt give me
1 messages · Page 1 of 1 (latest)
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
where did u try to log?
can you show the file again so its easier to look at in this thread?
C:\Users\tejee_n\Documents\GitHub\new-republic-bot>node index.js
{}
it logs it right there, no? ^
dir?
sorry, directory
directory structure
ie
src/commands/ping.js
or
src/commands/system/ping.js
how would i get that directory
You see it in your file explroer or in your vscode (f.ex)
example of mine
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))
}
oh ok lol
if possible can we see what pvpclose looks like
wait, did u log file or bot.name.commands in the code above?
ok
file
it didnt reach bot.name.commands
yeah sure
I havent actually started working on the code within it, so its the same as the pvp request
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)
no worries im more looking for the structure of the file
did this ever work?
and the other one is same exact?
im not using subcommands anymore
yes lol
It did until file just randomly decided to off itself
should be yea
that could be partly why
reason for asking it will read the other file first
why would it read the other one first
the way its ordered in the file system
oh ok
but needs name and data
I have a switch case that was working in my other file
maybe i thought to far ahead
before
const file = require('./Commands/${command}')
can you log command (console.log(command))
{
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]
also i totally forgot to ask where is this file located in the directory
no
thats all it logged?
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
can u give me an updated this
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
yea remove console.log(bot.name.commands)
that seems to have worked, now its just telling me the names need to be different
Thanks for your help
for (const command of commands) {
console.log(command)
this part should be printing both files
ye
thats the other part i was just getting to lol
how did i miss that console log damn