Node js not starting

Hi, sorry if I do something wrong but I'm really new to this world. My problem is that I made a code for a bot in Visual Studio Code and the command "node index.js" in the terminal to make the bot go online and start nodejs doesn't work. I contacted the discord dev server and they invited me here, sorry if what I'm writing is not relevant with the topic of this channel. Here's the code and the discord.js version is 14.13.0.
const { Client, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.once(Events.ClientReady, c => {
console.log(`Ready! Logged in as ${c.user.tag}`);
});
client.login(token);
const { Client, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.once(Events.ClientReady, c => {
console.log(`Ready! Logged in as ${c.user.tag}`);
});
client.login(token);
27 Replies
d.js toolkit
d.js toolkit10mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by staff
_Chri07_
_Chri07_10mo ago
discord.js@14.13.0 V20.6.1
Булочка | pasha_boez
What you get in your console? After write "node index.js"
_Chri07_
_Chri07_10mo ago
Nothing, if I write node index.js and press enter it's like I didn't wrote anything It re-appears the file path One moment I'll show you
_Chri07_
_Chri07_10mo ago
No description
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
_Chri07_
_Chri07_10mo ago
Yeah I did I have it in visual studio code Okay I will save it manually but if I do I solve th problem? In the dev discord server they told me to change EventsClientready with ready instead but idk what it means No I don't, I know a bit about programming but not in js. I'm sorry but I don't have much knowledge even of client, and something like that. I followed a guide on Google pass by pass, I can indicate it to you if you want to know what I did As I said I come from discord dev server and they gave me the link for that guide
d.js docs
d.js docs10mo ago
guide Home: Introduction read more
_Chri07_
_Chri07_10mo ago
Yes Of course, give me a minute
_Chri07_
_Chri07_10mo ago
No description
_Chri07_
_Chri07_10mo ago
Okay, closing vstudiocode I clicked on file->save, is it okay or I have to save all the files separately? I saved them separately but now visual studio code tells me that there are multiple problems on the code It says that token is assigned a value but never used and that the strings must be use singoequote
_Chri07_
_Chri07_10mo ago
No description
_Chri07_
_Chri07_10mo ago
Okay so you can confirm to me that the code is right and should work? If so and it doesn't work I will contact the discord devs again Hi, sorry again, i implemented my code but i have this error, what you think the problem is?
C:\Users\chris\OneDrive\Documenti\Desktop\bot presenze\node_modules\discord.js\src\util\BitField.js:172
throw new DiscordjsRangeError(ErrorCodes.BitFieldInvalid, bit);
^

RangeError [BitFieldInvalid]: Invalid bitfield flag or number: undefined.
at IntentsBitField.resolve (C:\Users\chris\OneDrive\Documenti\Desktop\bot presenze\node_modules\discord.js\src\util\BitField.js:172:11)
at C:\Users\chris\OneDrive\Documenti\Desktop\bot presenze\node_modules\discord.js\src\util\BitField.js:167:54
at Array.map (<anonymous>)
at IntentsBitField.resolve (C:\Users\chris\OneDrive\Documenti\Desktop\bot presenze\node_modules\discord.js\src\util\BitField.js:167:40)
at new BitField (C:\Users\chris\OneDrive\Documenti\Desktop\bot presenze\node_modules\discord.js\src\util\BitField.js:33:38)
at new IntentsBitField (C:\Users\chris\OneDrive\Documenti\Desktop\bot presenze\node_modules\discord.js\src\util\IntentsBitField.js:9:1)
at Client._validateOptions (C:\Users\chris\OneDrive\Documenti\Desktop\bot presenze\node_modules\discord.js\src\client\Client.js:511:25)
at new Client (C:\Users\chris\OneDrive\Documenti\Desktop\bot presenze\node_modules\discord.js\src\client\Client.js:78:10)
at Object.<anonymous> (C:\Users\chris\OneDrive\Documenti\Desktop\bot presenze\index.js:4:16)
at Module._compile (node:internal/modules/cjs/loader:1241:14) {
code: 'BitFieldInvalid'
}

Node.js v20.6.1
C:\Users\chris\OneDrive\Documenti\Desktop\bot presenze\node_modules\discord.js\src\util\BitField.js:172
throw new DiscordjsRangeError(ErrorCodes.BitFieldInvalid, bit);
^

RangeError [BitFieldInvalid]: Invalid bitfield flag or number: undefined.
at IntentsBitField.resolve (C:\Users\chris\OneDrive\Documenti\Desktop\bot presenze\node_modules\discord.js\src\util\BitField.js:172:11)
at C:\Users\chris\OneDrive\Documenti\Desktop\bot presenze\node_modules\discord.js\src\util\BitField.js:167:54
at Array.map (<anonymous>)
at IntentsBitField.resolve (C:\Users\chris\OneDrive\Documenti\Desktop\bot presenze\node_modules\discord.js\src\util\BitField.js:167:40)
at new BitField (C:\Users\chris\OneDrive\Documenti\Desktop\bot presenze\node_modules\discord.js\src\util\BitField.js:33:38)
at new IntentsBitField (C:\Users\chris\OneDrive\Documenti\Desktop\bot presenze\node_modules\discord.js\src\util\IntentsBitField.js:9:1)
at Client._validateOptions (C:\Users\chris\OneDrive\Documenti\Desktop\bot presenze\node_modules\discord.js\src\client\Client.js:511:25)
at new Client (C:\Users\chris\OneDrive\Documenti\Desktop\bot presenze\node_modules\discord.js\src\client\Client.js:78:10)
at Object.<anonymous> (C:\Users\chris\OneDrive\Documenti\Desktop\bot presenze\index.js:4:16)
at Module._compile (node:internal/modules/cjs/loader:1241:14) {
code: 'BitFieldInvalid'
}

Node.js v20.6.1
treble/luna
treble/luna10mo ago
You provided an invalid intent
_Chri07_
_Chri07_10mo ago
Thanks, can I send you my intents list so you can tell me what is wrong? The code is too long to be sent by message
Pulse
Pulse10mo ago
for now you can just send your intents, so your new Client({intents:[...]}) statement
_Chri07_
_Chri07_10mo ago
Okay I will, give me a minute
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageReactionAdd,
],
});
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageReactionAdd,
],
});
Pulse
Pulse10mo ago
GatewayIntentBits.MessageReactionAdd is not a real intent maybe you wanted GatewayIntentBits.GuildMessageReactions?
_Chri07_
_Chri07_10mo ago
Maybe, as I said it's an AI generated code as I don't know much of js so could be. Same error I think I tried How can I send you the entire code? I cannot in this message because it's too long Now it works I saved the file and apparently works To make a command to call the bot i have to insert it here after the /? const prefix = '/';
treble/luna
treble/luna10mo ago
You should not trust ai Basic js knowledge is required as per #rules 3
_Chri07_
_Chri07_10mo ago
Yeah I know I'm sorry I was invited to this server by discord devs and I started approaching developing in js recently But I know a bit about programming so I'm not really in a bad situation
treble/luna
treble/luna10mo ago
Well then you should follow the guide Not ask ai to do it for you because then you'll end up like this
_Chri07_
_Chri07_10mo ago
Okay thank you for helping, I can use the ai generated code as a base? I understand that maybe as chatGPT is outdated gives me the wrong code
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs10mo ago
guide Home: What's new read more
treble/luna
treble/luna10mo ago
Use the guide
_Chri07_
_Chri07_10mo ago
Okay guys thank you so much for helping:)