diff --git a/events/interactionCreate.js b/events/interactionCreate.js index 49c59a3..87b69bb 100644 --- a/events/interactionCreate.js +++ b/events/interactionCreate.js @@ -206,12 +206,17 @@ module.exports = { } catch (error) { error.errorContext = `[InteractionCreate]: an error occurred while executing the ${command.data.name} command.`; client.emit("error", error); - await interaction.editReply({ + const commandErrorReply = { content: config.errors.command_error || "There was an error while executing this command!", flags: MessageFlags.Ephemeral, - }); + }; + if (interaction.deferred || interaction.replied) { + await interaction.editReply(commandErrorReply); + } else { + await interaction.reply(commandErrorReply); + } } } else if (interaction.isStringSelectMenu()) { if (interaction.customId === "categoryMenu") { diff --git a/utils/mainUtils.js b/utils/mainUtils.js index 64eacfd..e490976 100644 --- a/utils/mainUtils.js +++ b/utils/mainUtils.js @@ -36,7 +36,10 @@ async function logMessage(message) { async function checkSupportRole(interaction) { const foundId = await ticketsDB.get(`${interaction.channel.id}.button`); - const allowedRoles = ticketCategories[foundId].support_role_ids; + const allowedRoles = ticketCategories[foundId]?.support_role_ids; + if (!allowedRoles) { + return false; + } return interaction.member.roles.cache.some((role) => allowedRoles.includes(role.id), ); diff --git a/utils/ticketClose.js b/utils/ticketClose.js index 419a540..48090ce 100644 --- a/utils/ticketClose.js +++ b/utils/ticketClose.js @@ -20,13 +20,24 @@ const { } = require("./mainUtils.js"); async function closeTicket(interaction, reason = "No reason provided.") { + const ticketCreatorID = await ticketsDB.get( + `${interaction.channel.id}.userID`, + ); + const ticketUserID = ticketCreatorID ? await getUser(ticketCreatorID) : null; + if (!ticketUserID) { + await logMessage( + `Could not close the ticket in channel ${interaction.channel.id}: its database entry has no creator, or the creator could not be fetched.`, + ); + await interaction.editReply({ + content: + "The ticket data for this channel is missing, so it cannot be closed. Delete the channel manually instead.", + }); + return; + } await ticketsDB.set( `${interaction.channel.id}.closeUserID`, interaction.user.id, ); - const ticketUserID = await getUser( - await ticketsDB.get(`${interaction.channel.id}.userID`), - ); const claimUserID = await ticketsDB.get( `${interaction.channel.id}.claimUser`, );