【问题标题】:"CLIENT_MISSING_INTENTS" in VSC Terminal - discord.js v13VSC 终端中的“CLIENT_MISSING_INTENTS”-discord.js v13
【发布时间】:2021-11-24 11:16:44
【问题描述】:

我正在尝试制作一个不和谐的机器人,但它一直在说:[Symbol(code)]: 'CLIENT_MISSING_INTENTS` 我非常困惑为什么会这样做,我尝试研究但没有任何帮助。

我的代码:

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)

【问题讨论】:

  • 这是你的全部代码还是你遗漏了不和谐和意图的require
  • IntentsDiscordJS 来自哪里?
  • 我相信GUILDS_MESSAGES 是一个无效的意图。应该是GUILD_MESSAGES(没有“S”)
  • 这能回答你的问题吗? Client Missing Intents when i try to launch it

标签: node.js npm discord.js


【解决方案1】:

确保你做两件事:

1.) 确保您包含来自 discord.js

Intents

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

2.) Intents.FLAGS.GUILDS_MESSAGES 应该是 Intents.FLAGS.GUILD_MESSAGES。只需从GUILDS 中删除S

所以你的代码应该是这样的:

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)

【讨论】:

  • 如果他们只使用模块导入,它将是import { Client, Intents } from "discord.js"
【解决方案2】:

快速修复:

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)

您的代码中的错误:

1:

您忘记从“discord.js”导入“DiscordJS”

2:

你用过:

错误: Intents.FLAGS.GUILDS_MESSAGES 哪个是错的……正确的:

正确: Intents.FLAGS.GUILD_MESSAGES

3:

你得到了:

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

在您的代码中,这是错误的,首先您应该创建一个在发送新消息时触发的事件。

示例:

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?',
        })
    }
})

【讨论】:

    猜你喜欢
    • 2021-11-09
    • 2021-10-25
    • 2021-10-16
    • 1970-01-01
    • 2021-10-20
    • 1970-01-01
    • 2021-10-09
    • 2021-12-24
    • 2022-01-05
    相关资源
    最近更新 更多