#An error when i try node main.js, im absolutely new at javascript and i wanna try to do my small bot

47 messages · Page 1 of 1 (latest)

past cradle

PS C:\Users\User\Desktop\Discord Bot> node main.js
node:internal/modules/cjs/loader:1327
throw err;
^

SyntaxError: C:\Users\User\Desktop\Discord Bot\config.json: Unexpected token : in JSON at position 7
at parse (<anonymous>)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module.require (node:internal/modules/cjs/loader:1143:19)
at require (node:internal/modules/cjs/helpers:110:18)
at Object.<anonymous> (C:\Users\User\Desktop\Discord Bot\main.js:2:17)
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)

Node.js v18.16.1 (Here is the error)
const { Client, Intents} = require('discord.js');
const {token} = require('./config.json');
const client = new Clent({intents: [Intents.FLAGS.guilds]});
client.once('ready', ()=>{
console.log('Ready!');
})
client.login(token); (Here is my code)

hushed canopy
past cradle

In config.json

hushed canopy
past cradle

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

hushed canopy

oh

sorry

i didnt see the whole thing

past cradle

np

hushed canopy

wait

why is token in parantheses

is it a v14 thing cuz idk about that

past cradle

its a v14

hushed canopy

const { token: token } = require('./config.json');

try this

works?

past cradle

well, atleast, here is a different error

C:\Users\User\Desktop\Discord Bot\main.js:3
const client = new Client({intents: [Intents.FLAGS.guilds]});
^

TypeError: Cannot read properties of undefined (reading 'FLAGS')
at Object.<anonymous> (C:\Users\User\Desktop\Discord Bot\main.js:3:46)
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

hushed canopy

const client = new Client({
intents: 32767,
}); try this

insterad of that

never mind i dont think that will work thats v13

hushed canopy

like thats all the code there is?

past cradle

wait

hushed canopy

if yes , then replace the whole thing with this js const { Client, Intents } = require('discord.js'); const { token: token } = require('./config.json'); const client = new Client({ intents: [Intents.FLAGS.guilds] }); client.once('ready', () => { console.log('Ready!'); }); client.login(token);

it will work

hushed canopy
past cradle wait

and also a tip , you just revealed ur token to everyone which eliminates the use of a config file so if i were you id reset it

past cradle

damn

bro

its worked

hushed canopy
past cradle

Tysm man

hushed canopy

try that once

the latter

past cradle

A

K

hushed canopy

which i gave

if it doesnt

then use the previous

and reset ur token

past cradle

alr reseted

hushed canopy