【问题标题】:Why do i keep getting error when typing node . or node main.js为什么我在输入 node 时总是出错。或节点 main.js
【发布时间】:2021-11-11 00:39:51
【问题描述】:

我遵循了 Codelyon 的教程。我以前跟着它,但现在它不起作用。我不知道我是否只是输入了错误而看不到它,或者我是否错过了完全不同的东西。澄清一下,是的,我在输入 node .node main.js 之前保存了

代码

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

 const client = new Discord.Client();



client.once('ready', () => {
    console.log('Kilobot is online')
});




client.login('bot token');

错误:

TypeError [CLIENT_MISSING_INTENTS]:必须为客户端提供有效的意图。

【问题讨论】:

标签: javascript node.js discord discord.js


【解决方案1】:

AFAIK,在新版本中,您需要在执行任何工作之前指定意图。这是文档中的link

// Require the necessary discord.js classes
const { Client, Intents } = require('discord.js');
const { token } = require('./config.json');

// Create a new client instance
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });

// When the client is ready, run this code (only once)
client.once('ready', () => {
    console.log('Ready!');
});

// Login to Discord with your client's token
client.login(token);

你的问题已经在stackoverflow上被问到了,here

【讨论】:

  • 确实,这是正确的答案。看来 OP 遵循的 Codelyon 教程已经过时,并且很可能使用 discord.js v11 而不是最新版本。如需更多文档,here 是所有意图及其对应的事件/数据的列表。
  • 是的,可能就是这样。但是如果他/她有任何错误,请等待他/她做出回应。感谢您指出可能的意图。
猜你喜欢
  • 2021-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-18
  • 2019-09-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多