【问题标题】:Coding a discord bot on discord.js and i keep getting the error "TypeError [ClientMissingIntents]: Valid intents must be provided for the Client."在 discord.js 上编写一个不和谐的机器人,我不断收到错误“TypeError [ClientMissingIntents]:必须为客户端提供有效的意图。”
【发布时间】:2022-07-20 00:42:14
【问题描述】:

当我尝试运行代码时,它给了我错误“TypeError [ClientMissingIntents]:必须为客户端提供有效的意图。”。我尝试使用节点。和 node main.js 运行它。我遵循了一个 yt 教程,它看起来应该可以工作。

这是我的代码:

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

const client = new Discord.Client();

const token = 'TOKEN HERE'

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

client.login(token);

【问题讨论】:

    标签: javascript discord discord.js bots


    【解决方案1】:

    从discord.js v13 开始,您在声明客户时需要 Intent。您可以通过以下方式添加它们:

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

    更多信息,我建议你去这里 => Gateway Intents

    【讨论】:

      猜你喜欢
      • 2022-06-19
      • 2021-10-14
      • 2021-10-17
      • 2021-12-02
      • 2018-07-21
      • 1970-01-01
      • 2021-10-12
      • 1970-01-01
      • 2021-05-23
      相关资源
      最近更新 更多