TypeError this client incrementMaxListeners is not a function

0 votes

I'm making a command for my discord bot and i get the error "This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
TypeError: this.client.incrementMaxListeners is not a function
    at new MessageCollector" which i barely understand
code:

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

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", message => {

                                imageURL = message.content(1);

                                

                            

      

                                // 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: "Order Description",

                                                            value: order.order,

                                                        }, {

                                                            name: "Order ID",

                                                            value: ticketID,

                                                        }, {

                                                            name: "Order Status",

                                                            value: "Ready", 

                                                        }],

                                                        timestamp: new Date(),

                                                        footer: {

                                                            text: `From ${api.client.guilds.get(order.guildID).name} `

                                                        }

                                                    }});

                                                });

    

                                                // 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.`));

        }

    });

};

Dec 28, 2020 in Web Development by anonymous
• 120 points
135 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Web Development

0 votes
1 answer
0 votes
1 answer

What is a Favicon, and Why is It Important?

A favicon is your website logo that ...READ MORE

answered Jan 30, 2020 in Web Development by Niroj
• 82,720 points
241 views
0 votes
1 answer

is there any way to download truffle? how to solve this error

Hello @ aishah , It seems likely that this is ...READ MORE

answered May 25, 2020 in Web Development by Niroj
• 82,720 points
181 views
0 votes
1 answer

NameError: name '_' is not defined

Hello, Just include this in you snippet: from django.utils.translation ...READ MORE

answered Aug 3, 2020 in Web Development by Niroj
• 82,720 points
813 views
0 votes
1 answer

Error: Failed to load resource: the server responded with a status of 404 (Not Found)

Your files are not under the JSP folder that's ...READ MORE

answered Dec 16, 2020 in Web Development by Gitika
• 65,870 points
4,256 views
0 votes
1 answer

Node js nodemiler Status 250 ok but mail is not received

Hi, @Sagar, I think you might simply be queuing the ...READ MORE

answered Dec 24, 2020 in Web Development by Gitika
• 65,870 points
256 views
0 votes
1 answer

How to send Bitcoins with node.js?

This website https://blockr.io/tx/push will successfully do the bitcoin transaction. You ...READ MORE

answered Jul 20, 2018 in Blockchain by Christine
• 15,830 points
1,273 views
0 votes
1 answer

Running a childProcess as shell script with node.js server

Here's what I think, you could pass ...READ MORE

answered Aug 14, 2018 in IoT (Internet of Things) by DataKing99
• 8,240 points
153 views
0 votes
1 answer

How to read the ETH value and other token values from an account?

You can do this eth.accounts shows you all known ...READ MORE

answered Oct 22, 2018 in Blockchain by Omkar
• 69,130 points
144 views