首页 > 解决方案 > 节点。制作不和谐机器人时不工作

问题描述

所以我想做一个不和谐的机器人,当我输入 node 时。进入 CMD 它给了我一个错误。我的代码在下面

const { Client, Intents } = require('discord.js');

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

const client = new Discord.Client();

client.once('ready', () => {
    console.log('Better Call Saul!');
});


client.login('The code'); 

错误:

抛出新的 TypeError('CLIENT_MISSING_INTENTS'); ^ TypeError [CLIENT_MISSING_INTENTS]:必须为客户端提供有效的意图。在 Client._validateOptions (C:\Users\Uzivatel\Desktop\joe\node_modules\←[4mdiscord.js←[24m\src\client\Client.js:544:13) 在新客户端 (C:\Users\Uzivatel\ Desktop\joe\node_modules\←[4mdiscord.js←[24m\src\client\Client.js:73:10) 在对象。(C:\Users\Uzivatel\Desktop\joe\main.js:3:16) ←[90m at Module._compile (node:internal/modules/cjs/loader:1101:14)←[39m ←[90m at Object .Module._extensions..js

标签: javascriptnode.jsdiscord.js

解决方案


看起来问题出在这里:

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

const client = new Discord.Client();

只有第一行有效。


推荐阅读