是否有办法将所有意图添加到v14中的Discord.js bot ?



我试图创建一个具有所有意图的新客户端,但我在网上没有找到解决这个问题的方法。下面是我的代码:

const Discord = require('discord.js')
const client = new Discord.Client({ intents: 7796 })
const { Client, GatewayIntentBits } = require("discord.js");
const client = new Client({
intents: Object.keys(GatewayIntentBits).map((a)=>{
return GatewayIntentBits[a]
}),
});

intents选项作为对象传递给Client构造函数。GatewayIntentBits对象是从Discord .js模块中导入的,它包含了所有可以与Discord API一起使用的可用意图的列表。

Object.keys()方法用于获取GatewayIntentBits对象中所有键的array。然后使用map()方法遍历数组中的每个键,并从GatewayIntentBits对象返回相应的值。

换句话说,这段代码正在创建一个启用了所有可用意图的新的Discord客户端。这对于从Discord API接收某些事件是必要的,例如消息事件等。