'Discord.js bot not logging in

I made a discord bot and i have no idea what's wrong with my code i mean look:

 const Discord = require("discord.js");
const client = new Discord.Client({
    intents: [
        "GUILDS",
        "GUILD_MESSAGES"
    ]
});

client.login('you thought haha')

I tried various tutorials but it's still not working



Solution 1:[1]

It's looking like about the intents and there's simple mistake as i've seen. If you wan't to open all intents i recommend you this;

const client = new Discord.Client({
    intents: new Discord.Intents(32767)
});

If you wan't specific intents then you should make them like;

const client = new Discord.Client({
intents: [Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_MESSAGES]
})

Also don't forget to open your intents from bot section on your developer panel!

More info here on docs.

Solution 2:[2]

I'm assuming you have already installed Node.js and discord.js, and also have a bot setup.

If you check discord.js Guide, they provide you the following code to start your bot:

// Require the necessary discord.js classes
const { Client, Intents } = require('discord.js');
const { token } = require('./config.json');

// Create a new client instance
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });

// When the client is ready, run this code (only once)
client.once('ready', () => {
    console.log('Ready!');
});

// Login to Discord with your client's token
client.login(token);

Then, open your terminal and run node index.js (assuming that your file name is index.js) to start the process. If you see "Ready!" after a few seconds, you're good to go!

I strongly recommend for you to follow this guide, it helped me a lot with the first steps with the discord bot.

Also, make sure that you have the right scopes selected for your bot: Bot scopes

Solution 3:[3]

I think the error is on the client declaration. You have to cap?talize the first letter of "intents". So the code becomes:

const Discord = require("discord.js");
const client = new Discord.Client({
    Intents: [
        "GUILDS",
        "GUILD_MESSAGES"
    ]
});
client.login("your token here");

And also please make sure that on your discord developers page you have your intents turned on.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 p-destri
Solution 3 flextzius