为什么 discord 中的客户端在 node.js 中会输出错误:TypeError: [CLIENT_MISSING_INTENTS]? [英] Why does the client in discord have an error that outputs: TypeError: [CLIENT_MISSING_INTENTS] in node.js?

查看:26
本文介绍了为什么 discord 中的客户端在 node.js 中会输出错误:TypeError: [CLIENT_MISSING_INTENTS]?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个目录,然后添加了一个 package.json 文件.我在 package.json 文件上安装了 dotenv 和 discord.js.我在目录中创建了一个 src 文件夹,然后将 bot.js 文件放在这个 src 文件夹中.代码是:

const Discord = require("discord.js");const client = new Discord.Client();client.on(准备好",() => {})client.login(process.env.BOT_TOKEN);

我输入节点 ./src/bot.js 并弹出错误.它说node_modules\discord.js\src\client\Client.js:544throw new TypeError('CLIENT_MISSING_INTENTS');"

是不是我做错了什么?

谢谢

解决方案

Discord.js v13 必须通过 意图到一个新的Client 实例.因此,为了修复错误,将所需的最低 Intent 作为参数传递给您的 client:

const { Client, Intents } = require(discord.js");const 客户端 = 新客户端({意图:[Intents.FLAGS.GUILDS,Intents.FLAGS.GUILD_MESSAGES],});client.on("ready", () => {});client.login(process.env.BOT_TOKEN);

<块引用>

要指定您希望机器人接收哪些事件,首先要考虑您的机器人需要运行哪些事件.然后选择所需的意图并将它们添加到您的客户端构造函数中,如下所示.

所有网关意图以及属于每个意图的事件都列在 Discord API 文档.

I made a directory and then added a package.json file. I installed dotenv and discord.js on the package.json file. I made a src folder inside the directory and then put the bot.js file inside this src folder. The code was:

const Discord = require("discord.js");
const client = new Discord.Client();

client.on("ready", () => {

})

client.login(process.env.BOT_TOKEN);

I typed in node ./src/bot.js and an error popped up. It said "node_modules\discord.js\src\client\Client.js:544 throw new TypeError('CLIENT_MISSING_INTENTS');"

Is there something I am doing wrong?

Thank you

解决方案

In Discord.js v13 it is mandatory to pass Intents to a new Client instance. So in order to fix the error pass the minimum required Intents as an argument to your client:

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

client.on("ready", () => {});

client.login(process.env.BOT_TOKEN);

To specify which events you want your bot to receive, first think about which events your bot needs to operate. Then select the required intents and add them to your client constructor, as shown below.

All gateway intents, and the events belonging to each, are listed on the Discord API documentation.

这篇关于为什么 discord 中的客户端在 node.js 中会输出错误:TypeError: [CLIENT_MISSING_INTENTS]?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆