Home > Enterprise >  "CLIENT_MISSING_INTENTS" in VSC Terminal - discord.js v13
"CLIENT_MISSING_INTENTS" in VSC Terminal - discord.js v13

Time:10-04

I'm trying to make a discord bot and it keeps saying: [Symbol(code)]: 'CLIENT_MISSING_INTENTS` I'm super confused why it's doing this, I tried researching but nothing has helped.

my code:

import dotenv from 'dotenv'
dotenv.config()

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

client.on('ready', () => {
    console.log('The bot is ready')
})

    if (message.content === 'amber') {
        message.reply({
            content: 'Hello, I see that you have called for me, need anything?',
        })
    }

 client.login(process.env.TOKEN)

CodePudding user response:

Make sure you do two things:

1.) Ensure you are including Intents from discord.js

const {Intents} = require('discord.js');

2.) Intents.FLAGS.GUILDS_MESSAGES should be Intents.FLAGS.GUILD_MESSAGES. Just remove the S from GUILDS

So your code should something like:

const DiscordJS = require('discord.js');
const {Intents} = require('discord.js');

import dotenv from 'dotenv'
dotenv.config()

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

client.on('ready', () => {
    console.log('The bot is ready')
})

    if (message.content === 'amber') {
        message.reply({
            content: 'Hello, I see that you have called for me, need anything?',
        })
    }

 client.login(process.env.TOKEN)

CodePudding user response:

Quick fix:

import DiscordJS, { Intents } from 'discord.js'
import dotenv from 'dotenv'
dotenv.config()

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

client.on('ready', () => {
    console.log('The bot is ready')
})

client.on('messageCreate', (message) => {
    if (message.content === 'amber') {
        message.reply({
            content: 'Hello, I see that you have called for me, need anything?',
        })
    }
  })
 client.login(process.env.TOKEN)

Mistakes you had in your code:

1:

You forgot to import "DiscordJS" from "discord.js"

2:

You used:

Wrong: Intents.FLAGS.GUILDS_MESSAGES Which is wrong... the correct one:

Correct: Intents.FLAGS.GUILD_MESSAGES

3:

You got:

    if (message.content === 'amber') {
        message.reply({
            content: 'Hello, I see that you have called for me, need anything?',
        })
    }

In your code, which is wrong, first of all you should create an event that triggers when a new message is sent.

Example:

client.on('messageCreate', (message) => { // "message" will be the message that triggered the event
    if (message.content === 'amber') {
        message.reply({
            content: 'Hello, I see that you have called for me, need anything?',
        })
    }
})
  • Related