类型错误:this.client.incrementMaxListeners 不是函数错误

时间:2020-12-21 10:45:00

标签: javascript node.js discord.js

我正在使用 javascript 制作一个不和谐的机器人,我在其中一个命令中遇到了这个错误,我几乎不明白出了什么问题,但错误说“这个错误是由于在没有 catch 块的情况下抛出异步函数而产生的,或者通过拒绝一个没有被 .catch() 处理过的承诺。这个承诺被拒绝的原因: 类型错误:this.client.incrementMaxListeners 不是函数”它在一段时间前工作正常命令的代码:

const fsn = require("fs-nextra");
const colors = require("colors");

exports.id = "setorder";

exports.onLoad = api => {
    api.commands.add("setorder", (msg) => {
        let employeeRole = msg.guild.roles.get("745410836901789749");

        if(msg.member.roles.has(employeeRole.id)) {
            if(msg.channel.id == 746423099871985755) {
                fsn.readJSON("./orders.json").then((orderDB) => {
                    let ticketID = msg.content.substring(10);
                    let order = orderDB[ticketID];

                    // If the order doesn't exist.
                    if(order === undefined) {
                        msg.reply("Couldn't find that order. Try again!");

                        return;
                    }
                    
                    // Checks status.
                    if(msg.author.id === order.chef) {
                        if (order.status === "Claimed") {
                            msg.reply("The next message you send in the next 10s will be set as the order's image.");
    
                            // Get the image URL.
                            let imageURL = undefined;
                            
                            const collector = new Discord.MessageCollector(msg.channel, m => m.author.id === msg.author.id, { time: 10000 });
                            collector.on("collect", async message => {
                                imageURL = message.content;
      
                                // Edits the message in the tickets channel.
                                api.client.channels.get("746423099871985755").fetchMessages({
                                    around: order.ticketChannelMessageID,
                                    limit: 1
                                }).then(messages => {
                                    const fetchedMsg = messages.first();
        
                                    // Edit the ticket in the tickets channel.
                                    fetchedMsg.edit({embed: {
                                        color: 0xFFFFFF,
                                        title: api.client.users.get(order.userID).username,
                                        fields: [{
                                            name: "Order Description",
                                            value: order.order,
                                        }, {
                                            name: "Order ID",
                                            value: ticketID,
                                        }, {
                                            name: "Order Status",
                                            value: "Ready.",
                                        }],
                                        timestamp: new Date(),
                                        footer: {
                                            text: `From ${msg.guild} (${msg.guild.id})`
                                        }
                                    }}).then((m) => {
                                        m = m.id;
        
                                        // Update Status
                                        delete orderDB[ticketID];
        
                                        orderDB[ticketID] = {
                                            "orderID": order.orderID,
                                            "userID": order.userID,
                                            "guildID": order.guildID,
                                            "channelID": order.channelID,
                                            "order": order.order,
                                            "status": "Ready",
                                            "ticketChannelMessageID": m,
                                            "chef": msg.author.id,
                                            "imageURL": imageURL
                                        };
        
                                        // Writes Data to JSON.
                                        fsn.writeJSON("./orders.json", orderDB, {
                                            replacer: null,
                                            spaces: 4
                                        }).then(() => {
                                            // Sends a message to the cook.
                                            msg.channel.send(`Alright, you've set \`${ticketID}\`  It's ready to be delivered`);
    
    
    
                                                // Update Status
                                                delete orderDB[ticketID];
                
                                                orderDB[ticketID] = {
                                                    "orderID": order.orderID,
                                                    "userID": order.userID,
                                                    "guildID": order.guildID,
                                                    "channelID": order.channelID,
                                                    "order": order.order,
                                                    "status": "Ready",
                                                    "ticketChannelMessageID": m,
                                                    "chef": msg.author.id,
                                                    "imageURL": imageURL
                                                };
    
                                                // Edits the message in the tickets channel.
                                                api.client.channels.get("746423099871985755").fetchMessages({
                                                    around: order.ticketChannelMessageID,
                                                    limit: 1
                                                }).then(messages => {
                                                    const fetchedMsg = messages.first();
    
                                                    fetchedMsg.edit({embed: {
                                                        color: 0xFFFFFF,
                                                        title: api.client.users.get(order.userID).username,
                                                        fields: [{
                                                            name: "New Order",
                                                            value: `${api.client.users.get(order.userID).username} would like to order.`,
                                                        }, {
                                                            name: "Order Description",
                                                            value: order.order,
                                                        }, {
                                                            name: "Order ID",
                                                            value: ticketID,
                                                        }, {
                                                            name: "Guild Infomation",
                                                            value: `This ticket came from ${api.client.guilds.get(order.guildID).name} (${order.guildID}) in #${api.client.channels.get(order.channelID).name} (${api.client.channels.get(order.channelID).id}).`,
                                                        }, {
                                                            name: "Order Status",
                                                            value: "Ready", 
                                                        }],
                                                        timestamp: new Date(),
                                                        footer: {
                                                            text: "Taco Bot"
                                                        }
                                                    }});
                                                });
    
                                                // Writes Data to JSON.
                                                fsn.writeJSON("./orders.json", orderDB, {
                                                    replacer: null,
                                                    spaces: 4
                                                }).then(() => {
                                                    
    
                                                    
                                                }).catch((err) => {
                                                    if (err) {
                                                        msg.reply(`There was an error while writing to the database! Show the following message to a developer: \`\`\`${err}\`\`\``);   
                                                    }
                                                });
                                            }
                                        ).catch((err) => {
                                            if (err) {
                                                msg.reply(`There was an error while writing to the database! Show the following message to a developer: \`\`\`${err}\`\`\``);
                                            }
                                        });
                                        
                                    });
                                });
                            });
                        }else if(order.status === "Unclaimed") {
                            msg.reply("This order hasn't been claimed yet. Run `.claim [Order ID]` to claim it.");
                        }else if(order.status === "Waiting") {
                            msg.reply("This order is already claimed and in the waiting process. Wait a little bit, then run `.deliver [Order ID]` to deliver.");
                        }else if(order.status === "Ready") {
                            msg.reply("This order is already ready to be delivered. Run `.deliver [Order ID]` to deliver.");
                        }
                    }else {
                        msg.reply(`Only the chef of the order, ${api.client.users.get(order.chef).username} may do this order.`);
                    }
                });  
            }else {
                msg.reply("Please use this command in the correct channel.");
                console.log(colors.red(`${msg.author.username} used the setimage command in the wrong channel.`));
            }
        }else {
            msg.reply("You do not have access to this command.");
            console.log(colors.red(`${msg.author.username} did not have access to the setimage command.`));
        }
    });
};```

0 个答案:

没有答案