Discord.js bot not logging in - javascript

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

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.

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:

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.

Related

Members arent cached

I'm trying to make a selfbot and before receiving messages saying that's against Discord ToS, I take that risk. My bot sends messages only to people it already has a DM channel opened with, probably because members aren't cached.
I want my bot to send message to everyone in my server. How do I cache members on a selfbot?
Code:
const guild = client.guilds.cache.get("id");
if(!guild) return;
guild.members.fetch();
guild.members.cache.random().createDM().then((dm => {
dm.send("Dont forget to verify !").catch(e => console.log('error'))
})).catch(() => {});
console.log("message sent");
Server Members Intent Image
Image above shows example to this answer;
Did you enable SERVER MEMBERS INTENT when creating your Discord bot?
https://discord.com/developers/applications/"ClientId"/bot
And/or did you create a new discord client with the GUILD_MEMBERS intent?
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.GuildMembers
]
});
And whether or not you know the risks, you should NOT be using self bots.

How can I make bot receive DM on Discord js v14? [duplicate]

This question already has an answer here:
message.content doesn't have any value in Discord.js
(1 answer)
Closed 4 months ago.
module.exports = {
name: 'messageCreate',
execute(message) {
if (message.channel.type == 'DM') {
console.log('Dm recieved')
client.channels.get('1026279100626767924').send(message);
}
}
};
I created event handling by referring to the Discord JS guide. I want my bot to receive a DM and send that message to my admin channel.
But the bot is not recognizing the DM
What should I do
(I'm using a translator)
You can use messageCreate event for listening your bot's DMs.
client.on("messageCreate", async message => {
if (message.guild) return;
console.log(`Someone sent DM to me => ${message.content}`);
await client.channels.cache.get(CHANNEL_ID).send(messsage.content);
});
You need to include partials Channel and Messages configurations on creating client:
const client = new Client({
intents: [
GatewayIntentBits.DirectMessages,
GatewayIntentBits.MessageContent
],
partials: [
Partials.Channel,
Partials.Message
]
})
That solved it for me!
There could be a couple problems with this.
First off, it could be your Intents.
Intents allow your bot to process certain events.
The intents that you will want are:
DirectMessages
MessageContent (this one may not be required, I am unsure).
So, go to where you initialize your client. It should look something like this:
const Discord = require("discord.js");
const client = new Discord.Client();
and change it into this:
const Discord = require("discord.js");
const { GatewayIntentBits, Client } = Discord;
const client = new Client({
intents: [
GatewayIntentBits.DirectMessages
GatewayIntentBits.MessageContent
]
});
The second issue could be that your message handler isn't detecting it properly.
Like the other answer says, you should just determine if there is no Guild attached to the message.
client.on("messageCreate", async(message) => {
if(!message.guild) {
client.channels.cache.get("YOUR_ID").send(message);
}
});
There could be other issues, but those two are the most probable. Considering you're not getting any errors, I'd presume it's the first one, the issue with Intents.
Hope this helps!

DisallowedIntents if im run discord bot in terminal

const { Client, GatewayIntentBits } = require("discord.js");
const client = new Client({
intents: [
GatewayIntentBits.Guilds, //all problem here
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers
],
});
client.login("TOKEN");
You get this problem because you are accessing privileged intents. To fix this go to https://discord.com/developers/applications/ click on your bot. Then go to the section that says bot and scroll down to Privileged Gateway Intents. Enable server members and message content intent. After that it should be fixed.

Client Missing Intents Error (Discord.js)

So I've been working on a discord bot I made for about a year, although I stopped for a bit a couple months ago. Anyway, I was getting back into it, and last night a made a "-say (something)" command for my bot. It was working out just fine, but today, I check up on the bot again, and I start getting an error about how I didn't state valid intents, but this is my code (for the client intents).
const Discord = require('discord.js');
const client = new Discord.Client({ partials: ["MESSAGE", "CHANNEL", "REACTION"]});
If anyone knows what I'm doing wrong, I'd be super grateful if you could let me know.
Thanks!
const { Client, GatewayIntentBits , Partials } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
partials: [Partials.Message, Partials.Channel, Partials.Reaction]
)}
you need to use this if you are on v14

Discord Bot isn't responding

For some reason, the basic ping pong command isn't working. I copied and pasted it from a website, but I am not sure what is wrong with it.
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
client.login('hidden')
client.once('ready', () => {
console.log('Ready!');
});
client.on('interactionCreate', interaction => {
if (!interaction.isCommand()) return;
const { commandName } = interaction;
if (commandName === 'ping') {
interaction.reply('Pong.');
}
});
There is no log error which makes it weirder. I know it is connecting because the bot appears online when I do a node index.js in the cmd panel.
Firstly, I recommend that you fix the indentation at the beginning and move the client.login call to the end, as that's how the discord.js docs do it.
Additionally, are you sure you're using Discord.js v13? These events were added in v13, so if you run it with Discord.js v12, your bot will run, but your functions will never be called.
Otherwise, your code looks good (to me), but I'm not an expert.

Categories