如何修复 CLIENT_MISSING_INTENTS 错误?

New*_*wJs 26 javascript node.js discord discord.js

我开始学习discord.js,但现在我面临这个问题。我尝试了一些谷歌搜索,但无法修复它。

const Discord = require('discord.js');
// const Discord = require('discord.js');

// Using Intents class
const client = new Discord.Client();

client.on('message', (msg) => {
  // Send back a reply when the specific command has been written by a user.
  if (msg.content === '!hello') {
    msg.reply('Hello, World!');
  }
});

client.login('my_token');
Run Code Online (Sandbox Code Playgroud)

这是我收到的错误:

在此输入图像描述

Dre*_*egg 34

您需要使用网关意图指定您希望机器人接收的事件。

代替

const client = new Discord.Client();
Run Code Online (Sandbox Code Playgroud)

使用

const client = new Discord.Client({ intents: [Enter intents here] })
Run Code Online (Sandbox Code Playgroud)

例如

Discord.js v14:

const client = new Discord.Client({ intents: [
  Discord.GatewayIntentBits.Guilds,
  Discord.GatewayIntentBits.GuildMessages
]})
Run Code Online (Sandbox Code Playgroud)

Discord.js v13:

const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] })


这是另一个有用的页面:网关


  • 意图可帮助您控制机器人接收哪些事件。有关详细信息,请参阅特权意图。
  • 您需要node.js 16.6 或更高版本才能使用discord.js13。npm install node@16在外壳中。
  • 客户端事件列表位于 Client 的事件选项卡