【问题标题】:Uncaught TypeError [CLIENT_MISSING_INTENTS]: Valid intents must be provided for the Client [duplicate]未捕获的TypeError [CLIENT_MISSING_INTENTS]:必须为客户端提供有效的意图[重复]
【发布时间】:2021-12-02 08:04:46
【问题描述】:

嘿,我已经尝试了这里的几乎所有教程,但它仍然向我显示未捕获的打字错误..即使在我看到并做了其他人也有过的事情(我的意思是同样的问题)之后,它仍然会继续这样做(我的意思是同样的问题)但它只是赢了不行 每件事都没有奏效,我不知道该怎么办 我也尝试过表达意图,但它说 const client = new Discord.Client();需要改变或不知道该怎么做任何帮助对我来说真的很棒。 我的主要脚本是这样的:


require('dotenv').config();
const Discord = require('discord.js');
const fs = require('fs');



if(!fs.existsSync('./data/servers.json')) {
    console.log('servers.json does not exist');
    console.log('Creating servers.json...');
    fs.writeFileSync('./data/servers.json', '{}', err => {
        console.error(err);
    });
    console.log('Success!');
}
if(!fs.existsSync('./data/config.json')) {
    console.log('config.json does not exist');
    console.log('Creating config.json...');
    fs.writeFileSync('./data/config.json', '{"defaultPrefix": "!"}', err => {
        console.error(err);
    });
    console.log('Success!');
}
if(!process.env.DISCORD_TOKEN) {
    console.log('The DISCORD_TOKEN environment variable is not defined');
    if(!fs.existsSync('./.env')) {
        console.log('.env does not exist');
        console.log('Creating .env...');
        fs.writeFileSync('./.env', 'DISCORD_TOKEN=', err => {
            console.error(err);
        });
        console.log('Success!');
    }
    console.log('Please, set the DISCORD_TOKEN environment variable or add it in .env');
}

const servers = require('../exports/exports.js');
const defaultPrefix = require('../data/config.json').defaultPrefix;

const client = new Discord.Client();
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));

for(const file of commandFiles) {
    const command = require('./commands/' + file);
    client.commands.set(command.name, command);
}


client.once('ready', () => {
    client.user.setStatus('online');
    client.user.setActivity(defaultPrefix + 'help', {  type: 'LISTENING'  });
    console.log('Ready!');
});


client.on('message', message => {
    if (message.author.bot) return;
    let prefix = servers.getPrefix(message.guild.id);
    if(message.content.toLowerCase().startsWith(prefix)) {
        const args = message.content.toLowerCase().slice(prefix.length).split(' ');
        if(!client.commands.has(args[0])) return;
        try {
            client.commands.get(args[0]).execute(message, args.slice(1, args.length), prefix);
        }
        catch(err) {
            console.error(err);
            message.reply('Something went wrong while executing that command');
        }
    }
    else if(message.content.toLowerCase().startsWith(defaultPrefix + 'help')) {
        const args = message.content.toLowerCase().slice(prefix.length).split(' ');
        try {
            client.commands.get('help').execute(message, args.slice(1, args.length), prefix);
        }
        catch(err) {
            message.reply('Something went wrong while executing that command');
        }
    }
});

async function close() {
    console.log('Received terminate signal');
    console.log('Closing');
    process.exit();
}

process.on('SIGINT', close);
process.on('SIGTERM', close);
client.login(process.env.DISCORD_TOKEN);

【问题讨论】:

  • 您正在查看多年前的教程,专为 discord.js v11 设计。最新版本是 discord.js v13,情况发生了变化。在构建客户端时,您需要提供“意图”。查看official guide,并查看docs 上的意图列表。
  • 这个问题也是下一个问题的重复,可以回答你的问题:How do I fix CLIENT_MISSING_INTENTS error - Disord.js

标签: javascript node.js json discord.js client


【解决方案1】:

真正简单的解决方案是:

const client = new Client({
    intents: 32767
});

但您还需要在https://discord.com/developers 的机器人设置中启用所有意图

【讨论】:

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