Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript SyntaxError:意外的标识符/不一致的Bot编码_Javascript_Node.js_Discord - Fatal编程技术网

Javascript SyntaxError:意外的标识符/不一致的Bot编码

Javascript SyntaxError:意外的标识符/不一致的Bot编码,javascript,node.js,discord,Javascript,Node.js,Discord,我正在尝试使用node.js编写自己的discord bot。我每次都会遇到这个错误,我不知道问题出在哪里。我尝试了很多其他的编码方法,但都没有成功。我甚至读到人们做了什么,当他们有类似的事情,再次,没有任何结果 这是index.js文件/代码 const Discord = require('discord.js'); const client = new Discord.Client({ partials: ["MESSAGE", "CHANN

我正在尝试使用node.js编写自己的discord bot。我每次都会遇到这个错误,我不知道问题出在哪里。我尝试了很多其他的编码方法,但都没有成功。我甚至读到人们做了什么,当他们有类似的事情,再次,没有任何结果

这是index.js文件/代码

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

    const client = new Discord.Client({ partials: ["MESSAGE", "CHANNEL", "REACTION" ]});

    const prefix = '.';

    const fs = require('fs');

    client.command = 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', () => {
        console.log('Ready!');
    });

    client.on('message', message => {
        if (!message.content.startsWith(prefix) || message.author.bot ) return;

        const args = message.content.slice(prefix.length).split(/ +/);
        const command = args.shift().toLowerCase();

        if (command === 'clear') {
            client.commands.get('clear').execute(message, args);
        }

        if (command === 'reactionrole') {
            client.commands.get('reactionrole').execute(message, args, Discord, client);
        } 

    });

    client.login('TOKEN');
这就是我会犯的错误

    /Users/User/Desktop/discordbot/index.js:9
    client.command = new.Discord.Collection();
                         ^^^^^^^

    SyntaxError: Unexpected identifier
        at wrapSafe (internal/modules/cjs/loader.js:979:16)
        at Module._compile (internal/modules/cjs/loader.js:1027:27)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
        at Module.load (internal/modules/cjs/loader.js:928:32)
        at Function.Module._load (internal/modules/cjs/loader.js:769:14)
        at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
        at internal/main/run_main_module.js:17:47

您遇到的问题是:

client.command = new.Discord.Collection();
您有一个额外的
但缺少一个
,因此应该是这样的:

client.command = new Discord.Collection();

语法是:
new
,后跟空格,然后是要创建实例的内容。语法中没有点(
)。见:

只需使用与第一个相同的语法,在代码中正确使用
new

new.Discord.Collection()->
新建Discord.Collection()