首页 > 解决方案 > CLIENT_MISSING_INTENTS 与 d.js

问题描述

const Discord = require('discord.js');
const bot = new Discord.Client();
const client = new Client({ 
    disableMentions: "everyone",
    ws: {
        intents: ["GUILDS", "GUILD_MEMBERS", "GUILD_MESSAGES", "GUILD_PRESENCES"]
    }
 })

const token = 'my token';

bot.on('ready', () =>{
    console.log('This bot is online!')
})



bot.login(token)

当我运行“节点”时。这会导致此错误。当我添加意图时,我真的不明白吗?

C:\Users\User\OneDrive\Desktop\Discord bot\node_modules\discord.js\src\client\Client.js:544
      throw new TypeError('CLIENT_MISSING_INTENTS');
      ^

TypeError [CLIENT_MISSING_INTENTS]: Valid intents must be provided for the Client.
    at Client._validateOptions (C:\Users\User\OneDrive\Desktop\Discord bot\node_modules\discord.js\src\client\Client.js:544:13)
    at new Client (C:\Users\User\OneDrive\Desktop\Discord bot\node_modules\discord.js\src\client\Client.js:73:10)
    at Object.<anonymous> (C:\Users\User\OneDrive\Desktop\Discord bot\index.js:2:13)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47 {
  [Symbol(code)]: 'CLIENT_MISSING_INTENTS'
}

我是新手,所以当你发现我的明显缺陷时请善待。提前致谢!

标签: discord.js

解决方案


Intents 是v13中的新要求,现在您的意图中几乎没有问题,但这是一个很好的开始。您需要通过以下方式定义意图:

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

推荐阅读