【问题标题】:Discord - CLIENT_MISSING_INTENTS [duplicate]不和谐 - CLIENT_MISSING_INTENTS [重复]
【发布时间】:2021-12-31 03:41:46
【问题描述】:

谁能告诉我我做错了什么?我收到一条错误消息“CLIENT_MISSING_INTENTS”。我不确定这意味着什么,我试图查找它,我发现的唯一一件事是安装我已经安装的 node.js,我需要将它安装到 Visual Studio Code 还是类似的东西?

index.js:

const bot = new Discord.Client({ disableEveryone: true });
const botconfig = require("./botconfig.json");
const fs = require("fs");

bot.commands = new Discord.Collection();
bot.aliases = new Discord.Collection();

// Read Commands Folder
fs.readdir("./commands/", (err, files) =>{ 
    if(err) console.log(err);

    let jsfile = files.filter(f => f.split(".").pop() === "js");
    if(jsfile.length <= 0) {
        console.log("Couldn't find any commands!")
        return;
    }

    jsfile.forEach((f) => {
        let props = require(`./commands/${f}`);
        console.log(`${f} loaded!`);
        bot.commands.set(props.help.name, props);

        props.help.aliases.forEach(alias => {
            bot.alias.set(alias, props.help.name);
        })
    })
})

// Bot Online Message And Activity Message
bot.on("ready", async () => {
    console.log(`${bot.user.username} is online on ${bot.guilds.size} servers!`);
    bot.user.setActivity(`with ${bot.guilds.size} servers!`)
})

bot.on("message", async message => {
    
    // Check Channel Type
    if(message.channel.type === "dm") return;
    if(message.author.bot) return;

    // Set Prefix
    let prefix = botconfig.prefix;

    // Check Prefix, Define Args & Command
    if(!message.content.startsWith(prefix)) return;
    let args = message.content.slice(prefix.length).trim().split(/ */g);
    let cmd;
    cmd = args.shift().toLowerCase();
    let command;
    let commandfile = bot.commands.get(cmd.slice(prefix.length));
    if(commandfile) commandfile.run(bot, message, args);

    // Run Commands
    if(bot.commands.has(cmd)) {
        command = bot.commands.get(cmd);
    } else if (bot.aliases.has(cmd)) {
        command = bot.commands.get(bot.aliases.get(cmd));
    }
    try {
        command.run(bot, message, args);
    } catch (e) {
        return;
    }
})

bot.login(botconfig.token)

【问题讨论】:

    标签: node.js discord.js


    【解决方案1】:

    向客户端添加意图

    从 v13 更新开始,您必须包含一系列您的机器人可以使用的意图。

    例如:

    const bot = new Discord.Client({
      intents: ["GUILDS", "GUILD_MESSAGES"],
      disableEveryone: true
    });
    

    官方djs指南https://discordjs.guide/popular-topics/intents.html给出了更详细的解释

    如果这是你的第一个机器人

    打开https://discord.com/developers/applications 并前往您的应用程序页面。导航到左侧的“Bot”选项卡并滚动一下。启用两个“特权网关意图”

    这是可选的,但它允许您接收某些无法访问的事件。

    【讨论】:

    • 您不必在 discord.js v12 中添加 Intent,它们仅在 v13 中添加
    • 在 v12 中添加了 Intents...
    • 我在 v12 变更日志中只发现了关于“意图”的一件事:Document intent error code messages (f4b1b39),所以我对如何在 v12 中添加它们非常感兴趣,因为我能够在没有它们的情况下运行我的代码在这个版本=3
    • @PiggyPlex 意图在 v12 中添加,但仅在 v13 中需要
    • “但仅在 v13 中需要” - @PiggyPlex
    猜你喜欢
    • 2018-02-25
    • 2021-02-01
    • 2021-10-12
    • 2021-10-13
    • 2021-10-15
    • 2021-04-12
    • 2018-06-22
    • 1970-01-01
    • 2020-03-31
    相关资源
    最近更新 更多