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