currently having trouble making my discord bot, i don't know what the problem is because i just started learning js yesterday
here is my code:
const Discord = require('discord.js');
const client = new Discord.Client();
client.once('ready', () => {
console.log('Deception booted up!');
});
client.login('token');
and the error says:
C:\Users\name\OneDrive\Desktop\DiscordBots\node_modules\discord.js\src\client\Client.js:548
throw new TypeError('CLIENT_MISSING_INTENTS');
^
TypeError [CLIENT_MISSING_INTENTS]: Valid intents must be provided for the Client.
at Client._validateOptions (C:\Users\name\OneDrive\Desktop\DiscordBots\node_modules\discord.js\src\client\Client.js:548:13)
at new Client (C:\Users\kenneth08\OneDrive\Desktop\DiscordBots\node_modules\discord.js\src\client\Client.js:76:10)
at Object.<anonymous> (C:\Users\name\OneDrive\Desktop\DiscordBots\main.js:3:16)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
at node:internal/main/run_main_module:17:47 {
[Symbol(code)]: 'CLIENT_MISSING_INTENTS'
}
pls help
CodePudding user response:
I assume that you've been copying this from a tutorial, likely one that is at least a couple months old, maybe year or two. The problem is that Discord recently changed their bot user API. It used to be that you could simply log into the bot account and start doing things with it, but they've changed it so that you have to say up-front what sorts of things you'll be doing with it. For example, you might tell Discord that your bot will be sending messages, and then the only thing your bot will be allowed to do is send messages. Here's how you declare intents:
const Discord = require('discord.js');
const Intents = Discord.Intents;
const Client = Discord.Client;
// create a new intents object with the intents we want
const myIntents = new Intents([ Intents.FLAGS.DIRECT_MESSAGES ]);
// create the bot with the declared intents
const client = new Client({ intents: myIntents });
You can find a short article on using the intents gatway in Discord.JS here, and a list of all of the Discord intents here.
CodePudding user response:
If you are using v13 of discord.js you can use this code:
Instead of
const Discord = require('discord.js');
const client = new Discord.Client();
You can change it to
const { Client, Intents, MessageEmbed } = require('discord.js');
const client = new Client({ intents: [Intents.FLAG.DIRECT_MESSAGES] });
