Attempt to fix a crash with pagination reaction removal

This commit is contained in:
TheEssem 2021-01-16 23:46:07 -06:00
parent 3de4858b5a
commit 116ed94ca3

View file

@ -5,7 +5,6 @@ const client = require("../client.js");
module.exports = async (message, pages, timeout = 120000) => { module.exports = async (message, pages, timeout = 120000) => {
const manageMessages = message.channel.guild && (message.channel.guild.members.get(client.user.id).permission.has("manageMessages") || message.channel.permissionsOf(client.user.id).has("manageMessages")) ? true : false; const manageMessages = message.channel.guild && (message.channel.guild.members.get(client.user.id).permission.has("manageMessages") || message.channel.permissionsOf(client.user.id).has("manageMessages")) ? true : false;
let page = 0; let page = 0;
let deleted = false;
const currentPage = await message.channel.createMessage(pages[page]); const currentPage = await message.channel.createMessage(pages[page]);
const emojiList = ["◀", "🔢", "▶", "🗑"]; const emojiList = ["◀", "🔢", "▶", "🗑"];
for (const emoji of emojiList) { for (const emoji of emojiList) {
@ -42,7 +41,6 @@ module.exports = async (message, pages, timeout = 120000) => {
if (manageMessages) msg.removeReaction("▶", userID); if (manageMessages) msg.removeReaction("▶", userID);
break; break;
case "🗑": case "🗑":
deleted = true;
reactionCollector.emit("end"); reactionCollector.emit("end");
if (currentPage.channel.messages.get(currentPage.id)) currentPage.delete(); if (currentPage.channel.messages.get(currentPage.id)) currentPage.delete();
return; return;
@ -52,7 +50,9 @@ module.exports = async (message, pages, timeout = 120000) => {
} }
}); });
reactionCollector.once("end", () => { reactionCollector.once("end", () => {
if (!deleted && manageMessages) currentPage.removeReactions(); if (message.channel.messages.get(currentPage.id) && manageMessages) {
currentPage.removeReactions();
}
}); });
return currentPage; return currentPage;
}; };