Javascript TypeError:无法读取属性';id';试图制造不和时的未定义

Javascript TypeError:无法读取属性';id';试图制造不和时的未定义,javascript,node.js,bots,discord,discord.js,Javascript,Node.js,Bots,Discord,Discord.js,我试图创建一个简单的discord bot,但是每当我运行-setcaps命令时,我会得到: TypeError:无法读取未定义的属性“id” 我不确定是什么原因造成的。如果你能提供任何帮助,我将不胜感激。我不确定要添加什么来提供更多细节,我正在使用node.js的最新稳定版本并使用notpad进行编辑++ //调用包 const Discord=require('Discord.js'); const economy=require('discord-eco'); //为不一致定义客户端 c

我试图创建一个简单的discord bot,但是每当我运行
-setcaps
命令时,我会得到:

TypeError:无法读取未定义的属性“id”

我不确定是什么原因造成的。如果你能提供任何帮助,我将不胜感激。我不确定要添加什么来提供更多细节,我正在使用node.js的最新稳定版本并使用notpad进行编辑++

//调用包
const Discord=require('Discord.js');
const economy=require('discord-eco');
//为不一致定义客户端
const client=new Discord.client();
//我们必须定义一个主持人角色,即运行某些命令所需的角色的名称
const modRole='Sentinel';
//这将在收到消息时运行。。。
client.on('message',message=>{
//变数
让前缀='-';
让msg=message.content.toUpperCase();
//让我们也添加一些新的变量
让cont=message.content.slice(prefix.length).split(“”;//将前缀切掉,然后将其后的所有内容存储在按空格分割的数组中。
设args=cont.slice(1);//这将删除消息的命令部分,只留下后面的单词以空格分隔
//命令
//Ping-让我们创建一个快速命令,以确保一切正常!
if(message.content.toUpperCase()==`${prefix}PING`){
message.channel.send('Pong!');
}
//为管理员添加/删除资金
if(msg.startsWith(`${prefix}SETCAPS`){
//检查他们是否有modRole
如果(!message.member.roles.find(“name”,modRole)){//如果没有角色,请运行。。。
message.channel.send('**您需要角色'''+modRole+'`才能使用此命令…**');
返回;
}
//检查他们是否定义了金额
如果(!args[0]){
message.channel.send(`**您需要定义一个金额。用法:${prefix}SETCAPS**`);
返回;
}
//我们还应该确保args[0]是一个数字
if(isNaN(args[0])){
message.channel.send(`**金额必须是一个数字。用法:${prefix}SETCAPS**`);
return;//如果发送错误消息,请记住返回!这样代码的其余部分就不会运行。
}
//检查他们是否定义了用户
让defineduser='';
如果(!args[1]){//如果他们没有定义任何人,请将其设置为自己的。
defineduser=message.author.id;
}否则{//如果他们确实定义了某人,请运行此命令。。。
let firstsinded=message.sindements.users.first();
defineduser=第一个提到的.id;
}
//最后,运行这个..记住如果你使用的是帮会唯一的方法,请确保在末尾添加帮会ID,
economy.updateBalance(defineduser+message.guild.id,parseInt(args[0]))。然后((i)=>{//并确保始终将要添加的数字解析为整数
message.channel.send(`**用户定义的帐户中添加/减去了${args[0]}.*`)
});
}
//余额与货币
如果(msg==`${prefix}BALANCE`| | msg===`${prefix}MONEY`){//如果消息是~BALANCE或~MONEY,则将运行此操作
//附加提示:如果你想让价值观变得独一无二,只要在你请求时添加+message.guild.id即可。
economy.fetchBalance(message.author.id+message.guild.id)。然后((i)=>{//economy.fetchBalance获取用户id,找到它,并将数据与它一起放入i。
//让我们为此使用一个嵌入
const embed=new Discord.RichEmbed()
.setDescription(`**${message.guild.name}隐藏**`)
.setColor(0xff9900)//如果在十六进制颜色之前加上0x,则可以设置任何十六进制颜色。
.addField('Stash Owner',message.author.username,true)//true使嵌入内联。Account Holder是标题,message.author是值
.addField('Stash Contents',i.money,true)
//现在我们需要发送消息
message.channel.send({embed})
})
}
});
client.login('tokenhidden');

我不确定这是否是导致您出错的原因,但让我们试一试。我编辑了用户是否提到某人的检查

// Call Packages
const Discord = require('discord.js');
const economy = require('discord-eco');

// Define client for Discord
const client = new Discord.Client();
// We have to define a moderator role, the name of a role you need to run certain commands
const modRole = 'Sentinel';

// This will run when a message is recieved...
client.on('message', message => {

    // Variables
    let prefix = '-';
    let msg = message.content.toUpperCase();
    // Lets also add some new variables
    let cont = message.content.slice(prefix.length).split(" "); // This slices off the prefix, then stores everything after that in an array split by spaces.
    let args = cont.slice(1); // This removes the command part of the message, only leaving the words after it seperated by spaces

    // Commands

    // Ping - Let's create a quick command to make sure everything is working!
    if (message.content.toUpperCase() === `${prefix}PING`) {
        message.channel.send('Pong!');
    }

    // Add / Remove Money For Admins
    if (msg.startsWith(`${prefix}SETCAPS`)) {

        // Check if they have the modRole
        if (!message.member.roles.find("name", modRole)) { // Run if they dont have role...
            message.channel.send('**You need the role `' + modRole.name + '` to use this command...**');
            return;
        }

        // Check if they defined an amount
        if (!args[0]) {
            message.channel.send(`**You need to define an amount. Usage: ${prefix}SETCAPS <amount> <user>**`);
            return;
        }

        // We should also make sure that args[0] is a number
        if (isNaN(args[0])) {
            message.channel.send(`**The amount has to be a number. Usage: ${prefix}SETCAPS <amount> <user>**`);
            return; // Remember to return if you are sending an error message! So the rest of the code doesn't run.
        }

        // Check if they defined a user
        let defineduser = '';
        let user = message.mentions.users.first() || msg.author;
        defineduser = user.id

        // Finally, run this.. REMEMBER IF you are doing the guild-unique method, make sure you add the guild ID to the end,
        economy.updateBalance(defineduser + message.guild.id, parseInt(args[0])).then((i) => { // AND MAKE SURE YOU ALWAYS PARSE THE NUMBER YOU ARE ADDING AS AN INTEGER
            message.channel.send(`**User defined had ${args[0]} added/subtraction from their account.**`)
        });

    }

    // Balance & Money
    if (msg === `${prefix}BALANCE` || msg === `${prefix}MONEY`) { // This will run if the message is either ~BALANCE or ~MONEY

        // Additional Tip: If you want to make the values guild-unique, simply add + message.guild.id whenever you request.
        economy.fetchBalance(message.author.id + message.guild.id).then((i) => { // economy.fetchBalance grabs the userID, finds it, and puts the data with it into i.
            // Lets use an embed for This
            const embed = new Discord.RichEmbed()
                .setDescription(`**${message.guild.name} Stash**`)
                .setColor(0xff9900) // You can set any HEX color if you put 0x before it.
                .addField('Stash Owner', message.author.username, true) // The TRUE makes the embed inline. Account Holder is the title, and message.author is the value
                .addField('Stash Contents', i.money, true)


            // Now we need to send the message
            message.channel.send({
                embed
            })

        })

    }

});

client.login('TOKEN HIDDEN')
//调用包
const Discord=require('Discord.js');
const economy=require('discord-eco');
//为不一致定义客户端
const client=new Discord.client();
//我们必须定义一个主持人角色,即运行某些命令所需的角色的名称
const modRole='Sentinel';
//这将在收到消息时运行。。。
client.on('message',message=>{
//变数
让前缀='-';
让msg=message.content.toUpperCase();
//让我们也添加一些新的变量
让cont=message.content.slice(prefix.length).split(“”;//将前缀切掉,然后将其后的所有内容存储在按空格分割的数组中。
设args=cont.slice(1);//这将删除消息的命令部分,只留下后面的单词以空格分隔
//命令
//Ping-让我们创建一个快速命令,以确保一切正常!
if(message.content.toUpperCase()==`${prefix}PING`){
message.channel.send('Pong!');
}
//为管理员添加/删除资金
if(msg.startsWith(`${prefix}SETCAPS`){
//检查他们是否有modRole
如果(!message.member.roles.find(“name”,modRole)){//如果没有角色,请运行。。。
message.channel.send('**您需要角色'''+modRole.name+'`才能使用此命令…**');
返回;
}
//检查他们是否定义了金额
如果(!args[0]){
message.channel.send(`**您需要定义一个金额。用法:${prefix}SETCAPS**`);
返回;
}
//我们还应该确保args[0]是一个数字
if(isNaN(args[0])){
message.channel.send(`**金额必须为
// Call Packages
const Discord = require('discord.js');
const economy = require('discord-eco');

// Define client for Discord
const client = new Discord.Client();
// We have to define a moderator role, the name of a role you need to run certain commands
const modRole = 'Sentinel';

// This will run when a message is recieved...
client.on('message', message => {

    // Variables
    let prefix = '-';
    let msg = message.content.toUpperCase();
    // Lets also add some new variables
    let cont = message.content.slice(prefix.length).split(" "); // This slices off the prefix, then stores everything after that in an array split by spaces.
    let args = cont.slice(1); // This removes the command part of the message, only leaving the words after it seperated by spaces

    // Commands

    // Ping - Let's create a quick command to make sure everything is working!
    if (message.content.toUpperCase() === `${prefix}PING`) {
        message.channel.send('Pong!');
    }

    // Add / Remove Money For Admins
    if (msg.startsWith(`${prefix}SETCAPS`)) {

        // Check if they have the modRole
        if (!message.member.roles.find("name", modRole)) { // Run if they dont have role...
            message.channel.send('**You need the role `' + modRole.name + '` to use this command...**');
            return;
        }

        // Check if they defined an amount
        if (!args[0]) {
            message.channel.send(`**You need to define an amount. Usage: ${prefix}SETCAPS <amount> <user>**`);
            return;
        }

        // We should also make sure that args[0] is a number
        if (isNaN(args[0])) {
            message.channel.send(`**The amount has to be a number. Usage: ${prefix}SETCAPS <amount> <user>**`);
            return; // Remember to return if you are sending an error message! So the rest of the code doesn't run.
        }

        // Check if they defined a user
        let defineduser = '';
        let user = message.mentions.users.first() || msg.author;
        defineduser = user.id

        // Finally, run this.. REMEMBER IF you are doing the guild-unique method, make sure you add the guild ID to the end,
        economy.updateBalance(defineduser + message.guild.id, parseInt(args[0])).then((i) => { // AND MAKE SURE YOU ALWAYS PARSE THE NUMBER YOU ARE ADDING AS AN INTEGER
            message.channel.send(`**User defined had ${args[0]} added/subtraction from their account.**`)
        });

    }

    // Balance & Money
    if (msg === `${prefix}BALANCE` || msg === `${prefix}MONEY`) { // This will run if the message is either ~BALANCE or ~MONEY

        // Additional Tip: If you want to make the values guild-unique, simply add + message.guild.id whenever you request.
        economy.fetchBalance(message.author.id + message.guild.id).then((i) => { // economy.fetchBalance grabs the userID, finds it, and puts the data with it into i.
            // Lets use an embed for This
            const embed = new Discord.RichEmbed()
                .setDescription(`**${message.guild.name} Stash**`)
                .setColor(0xff9900) // You can set any HEX color if you put 0x before it.
                .addField('Stash Owner', message.author.username, true) // The TRUE makes the embed inline. Account Holder is the title, and message.author is the value
                .addField('Stash Contents', i.money, true)


            // Now we need to send the message
            message.channel.send({
                embed
            })

        })

    }

});

client.login('TOKEN HIDDEN')