discord.js - 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'
}
我是新手,所以当你发现我的明显缺陷时请善待。提前致谢!
解决方案
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]
});
推荐阅读
- python-3.x - 可视化传感器和树莓派的频率响应
- azure - Cosmos DB查询MIN函数获取最小id
- c# - 使用 GraphClient 的 Exchange Room 邮箱位置详细信息
- postscript - 如何确保 PostScript 中的垂直和水平线宽相同?
- kotlin - ReentrantReadWriteLock 在解锁时卡住
- regex - 根据条件从 GraphQL 中删除空格和换行符
- azure-devops - Azure 发布管道 - 发布到通用工件
- postgresql - Kubernetes 上的 Pgadmin4:将用户和设置保存在一个卷中
- python - 如何在python中操作巨大的csv并在执行之前知道函数的执行时间?
- javascript - 无法访问 HTMLElement