#"config" is not defined

79 messages · Page 1 of 1 (latest)

fierce narwhal
#
    at Object.<anonymous> (C:\Users\csj25\OneDrive\Desktop\discordbot\src\index.js:11:14)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47```
stiff sorrelBOT
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

fierce narwhal
#
const { Client, GatewayIntentBits, Partials } = require('discord.js');

const client = new Client({ intents: [GatewayIntentBits.Guilds], partials: [Partials.Channel] });
const config = require('./config.json');
config();



client.on('ready', () => {
    console.log(`${client.user.tag} is ready to go!`);
})


client.login(config.TOKEN);```
topaz cobalt
#

well 2 things-

  1. config is a json file, not a function
  2. make sure your file is saved
fierce narwhal
#

it is saved

topaz cobalt
#

here's really what your main file should look like according to the guide

fierce narwhal
#

what guid

#

e

topaz cobalt
#

the discord.js guide?

fierce narwhal
#

send

topaz cobalt
#

have you never seen the djs guide before? im curious

twilit coyoteBOT
#

guide Creating Your Bot: Creating the main file
read more

fierce narwhal
#

still dont work

fierce narwhal
topaz cobalt
#

instead of saying "it doesnt work" please be more specific. it doesnt help me

fierce narwhal
#
Require stack:
- C:\Users\csj25\OneDrive\Desktop\discordbot\src\index.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
    at Module._load (node:internal/modules/cjs/loader:922:27)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object.<anonymous> (C:\Users\csj25\OneDrive\Desktop\discordbot\src\index.js:2:19)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
  code: 'MODULE_NOT_FOUND',

  requireStack: [ 'C:\\Users\\csj25\\OneDrive\\Desktop\\discordbot\\src\\index.js' ]```
topaz cobalt
#

you have a .json file, not config.js

fierce narwhal
#

oh nvm

#

ok now

#
Require stack:
- C:\Users\csj25\OneDrive\Desktop\discordbot\src\index.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
    at Module._load (node:internal/modules/cjs/loader:922:27)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object.<anonymous> (C:\Users\csj25\OneDrive\Desktop\discordbot\src\index.js:2:19)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ 'C:\\Users\\csj25\\OneDrive\\Desktop\\discordbot\\src\\index.js' ]
}

Node.js v18.16.1```
topaz cobalt
#

either the file doesn't exist or its the wrong file path

fierce narwhal
#

do i move it in my source folder?

topaz cobalt
#

you can put it wherever you want, but the file path needs to be adjusted accordingly

fierce narwhal
#

soo const { TOKEN } = require('src/.config.json'); ?

topaz cobalt
#

not quite. that's not how file pathing works

twilit coyoteBOT
#
  • File paths explained in detail: learn more
  • . refers to the current directory
  • .. refers to the parent directory
  • Node path module: learn more
fierce narwhal
#

dont know what that is just say

topaz cobalt
#

you dont know what a file path is?

fierce narwhal
#

i do but ive never had to do this

#

yall shoulda never dropped support for v12skull_lmao

topaz cobalt
fierce narwhal
#

nah ill just remove it out of the source folder

topaz cobalt
fierce narwhal
#

still the same error

#
Require stack:
- C:\Users\csj25\OneDrive\Desktop\discordbot\src\index.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
    at Module._load (node:internal/modules/cjs/loader:922:27)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object.<anonymous> (C:\Users\csj25\OneDrive\Desktop\discordbot\src\index.js:2:19)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ 'C:\\Users\\csj25\\OneDrive\\Desktop\\discordbot\\src\\index.js' ]
}
topaz cobalt
#

fix your file path

fierce narwhal
#

thats what you showed me

topaz cobalt
#

my answer is the same

fierce narwhal
topaz cobalt
#

./ refers to the current directory

#

please read that tag again

fierce narwhal
#

thats what it is

topaz cobalt
#

no its not

#

your index.js is inside the src folder

fierce narwhal
#

okk? skull_lmao

topaz cobalt
#

please read the suggestions i have given you. i cannot repeat myself anymore

fierce narwhal
#

took it out of the src folder and

#
    at Object.<anonymous> (C:\Users\csj25\OneDrive\Desktop\discordbot\index.js:6:1)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47

Node.js v18.16.1```
fierce narwhal
#

okk? thats what you showed me lmao this isnt support skull_lmao

topaz cobalt
#

then what is it?

#

a json file is not a function

#

so remove the function

fierce narwhal
#

ok its gone

#

and still an error

topaz cobalt
#

which is?

fierce narwhal
#
    at Object.<anonymous> (C:\Users\csj25\OneDrive\Desktop\discordbot\index.js:5:1)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47
topaz cobalt
#

show me your updated code

fierce narwhal
#
const { Client, GatewayIntentBits, Partials } = require('discord.js');
const { TOKEN } = require('./config.json');

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



client.on('ready', () => {
    console.log(`${client.user.tag} is ready to go!`);
})


client.login(TOKEN);```
topaz cobalt
#

yeah its not defined

#

remove config()

fierce narwhal
#

you said config(); defined it yesterday

topaz cobalt
#

that was for your .env file which you don't seem to be using today

#

two different things

fierce narwhal
#

cus neither work

topaz cobalt
#

it does if you read the guide properly

#

instead of getting so defensive over it

#

im trying to help as best as i can

#

but you're not putting in enough effort for this

#

i highly suggest you make your main file look like this, but its just a suggestion so im not forcing you

#

this is mainly for best practice and should be used

fierce narwhal
topaz cobalt
#

use whatever library you want and that is your opinion

fierce narwhal
#

not an opinion everyone says it

topaz cobalt
#

do you still need help or no?

fierce narwhal
#

im good lil bro

topaz cobalt
#

because im not here to debate with you anymore. i wasted enough of my time

#

i wish you the best of luck with your project