“类型错误:无法读取属性‘我’的未定义”

时间:2021-01-07 14:49:05

标签: node.js discord.js

我正在做两个命令我discord.js V12的机器人,但它抛出错误“类型错误:无法读取属性‘我’的未定义”时使用的第一个命令的第一个命令的代码:

function generateID() {
    let ticketGen = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".split("");
    let ticketStr = "";

    for(let i = 0; i < 3; i++) {
        ticketStr += ticketGen[Math.floor(Math.random() * ticketGen.length)];
    }

    return ticketStr;
}
const fsn = require("fs-nextra");

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

module.exports = {
    name: 'order',
    description: 'Ordering something',
    args: 'true',
    usage: '<order desription>',
    aliases: ['o'],
    execute(message) {
        
        const client = message.client; //<- Line added right here
        
        let order = message.content.substring(7);
        let channel = message.guild.channels.cache.get("746423099871985755");
        let customer = message.author.id

        fsn.readJSON("./blacklist.json").then((blacklistDB) => {
            let entry = blacklistDB[message.guild.id];
            
            // Checks is server is blacklisted or not.
            if(entry === undefined) {
                // Gets ticket ID.
                const ticketID = generateID();
        
                // Sends ticket information to tickets channel.
                const exampleEmbed = new Discord.MessageEmbed()
                .setColor('#FFFF33')
                .setTitle(message.member.user.tag)
                .setAuthor(`Order ID: ${ticketID}`)
                .setDescription(order)
                .setThumbnail(message.author.avatarURL())
                .setTimestamp()
                .setFooter(`From ${message.guild.name} (${message.guild.id})`);
            
                channel.send(exampleEmbed);


        
                    // Sets ticket info.
                    fsn.readJSON("./orders.json").then(orderDB => {
                        // Set JSON information.
                        if (!orderDB[ticketID]) orderDB[ticketID] = {
                            "orderID": ticketID,
                            "userID": message.author.id,
                            "guildID": message.guild.id,
                            "channelID": message.channel.id,
                            "order": order,
                            "status": "Unclaimed",
                            "ticketChannelMessageID": "not set"
                        };
            
                        // Write JSON information.
                        fsn.writeJSON("./orders.json", orderDB, {
                            replacer: null,
                            spaces: 4
                        }).then(() => {
                            // Sends an embed to the customer.
                            message.channel.send("Your order has been sent and it will be delivered soon.")
            
                            // Logs in console.
                            console.log(colors.green(`${message.author.username} ordered "${order}" in ${message.guild.name} (${message.guild.id}) in ${message.channel.name} (${message.channel.id}).`));
                        }).catch((err) => {
                            if(err) {
                                message.reply(`There was a database error! Show the following message to a developer: \`\`\`${err}\`\`\``);
                                console.log(colors.red(`Error in order ${ticketID}: ${err}`));
                            }
                        });
                    });
                
            }else {
                message.reply("This server is currently blacklisted.");
            }
        });
    }
};

在这一部分,我觉得有什么不妥它是如何保存的信息?

  // Sets ticket info.
                    fsn.readJSON("./orders.json").then(orderDB => {
                        // Set JSON information.
                        if (!orderDB[ticketID]) orderDB[ticketID] = {
                            "orderID": ticketID,
                            "userID": message.author.id,
                            "guildID": message.guild.id,
                            "channelID": message.channel.id,
                            "order": order,
                            "status": "Unclaimed",
                            "ticketChannelMessageID": "not set"
                        };

                        // Write JSON information.
                        fsn.writeJSON("./orders.json", orderDB, {
                            replacer: null,
                            spaces: 4
                        }).then(() => {
                            // Sends an embed to the customer.
                            message.channel.send("Your order has been sent and it will be delivered soon.")

使用第二个命令返回错误时错误发生“类型错误:无法读取的‘我’未定义的属性”,我认为它与第一个命令做 第二命令代码:

if (order.status === "Ready") {
                        // Delete ticket from database.
                        delete orderDB[ticketID];

                        // Writes data to JSON.
                        fsn.writeJSON("./orders.json", orderDB, {
                            replacer: null,
                            spaces: 4
                        }).then(() => {
                            // If bot has create instant invite permission.
                            
                            if(client.guilds.cache.get(order.guildID).me.hasPermission("CREATE_INSTANT_INVITE")) {
                                // Send message to cook.
                                client.channels.cache.get(order.channelID).send(`${client.users.cache.get(order.userID)}, Here is your taco that you ordered. Remember you can do \`.tip [Amount]\` to give us virtual tips, and \`.feedback [Feedback]\` to give us feedback on how we did. ${order.imageURL}`);

                                message.reply(`Order has been sent to ${client.guilds.cache.get(order.guildID).name}`);
                                
                                
                                
                                
                            }else {
                                // Bot delivers it's self.
                                client.channels.cache.get(order.channelID).send(`${client.users.cache.get(order.userID)}, Here is your taco that you ordered. Remember you can do \`.tip [Amount]\` to give us virtual tips, and \`.feedback [Feedback]\` to give us feedback on how we did. ${order.imageURL}`);

我只包括我认为有错误,因为order.guildid是未定义的,但如何解决该部件

1 个答案:

答案 0 :(得分:0)

正如错误消息所解释的,没有未定义的属性 POINT p; std::vector<POINT> coordinates; while (cin >> p) { coordinates.push_back(p); } ,因此公会未定义/未找到。检查您使用的公会 ID 是否是正确的公会 ID,并且它是一个字符串而不是数字。可能值得在其中添加 me 以帮助确定问题。