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 29, 2020 in Web Development by anonymous
• 120 points
418 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
0 answers

jQuery(...).iris is not a function

I am trying to implement color picker ...READ MORE

Jul 28, 2022 in Web Development by gaurav
• 22,940 points
143 views
0 votes
1 answer

jquery - is not a function error

In Wordpress jQuery.noConflict() is called on the jQuery file ...READ MORE

answered Aug 4, 2022 in Web Development by rajatha
• 7,480 points
165 views
0 votes
1 answer

toaster.clear('*') does not work inside a jQuery function

The error - "TypeError: $.toast is not a ...READ MORE

answered Aug 5, 2022 in Web Development by rajatha
• 7,480 points
1,146 views
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,840 points
477 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,790 points
2,405 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
325 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,190 points
362 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP