diff --git a/src/events/autocomplete/unban.js b/src/events/autocomplete/unban.js index 36d1d29..91db9c4 100644 --- a/src/events/autocomplete/unban.js +++ b/src/events/autocomplete/unban.js @@ -6,7 +6,6 @@ module.exports = { /** @param { import("discord.js").AutocompleteInteraction } interaction */ async execute(interaction) { - if (!interaction.isAutocomplete()) return if (interaction.commandName !== "unban") return const focusedOption = interaction.options.getFocused(true) if (focusedOption.name !== "user") return diff --git a/src/utils/eventHandlers/autocomplete.js b/src/utils/eventHandlers/autocomplete.js index 8916e14..16daad2 100644 --- a/src/utils/eventHandlers/autocomplete.js +++ b/src/utils/eventHandlers/autocomplete.js @@ -14,7 +14,19 @@ function loadAutocompleteEvents(client) { const autocomplete = require(filePath) if ("name" in autocomplete && "execute" in autocomplete && autocomplete.type === "autocomplete") { - client.on(Events.InteractionCreate, autocomplete.execute) + client.on(Events.InteractionCreate, async interaction => { + if (!interaction.isAutocomplete()) return + + try { + await autocomplete.execute(interaction) + } catch (error) { + console.error(error) + await interaction.respond({ + content: "There was an error while executing this command!", + ephemeral: true + }) + } + }) } else { console.log(`[WARNING] The autocomplete at ${filePath} is missing a required "name", "execute" or "type" property.`) }