Updated autocomplete event handler

Signed-off-by: Taken <taken@mairimashita.org>
This commit is contained in:
2023-12-11 13:41:49 +01:00
parent ed8cc905bf
commit 325f4a9c0e
2 changed files with 13 additions and 2 deletions

View File

@@ -6,7 +6,6 @@ module.exports = {
/** @param { import("discord.js").AutocompleteInteraction } interaction */ /** @param { import("discord.js").AutocompleteInteraction } interaction */
async execute(interaction) { async execute(interaction) {
if (!interaction.isAutocomplete()) return
if (interaction.commandName !== "unban") return if (interaction.commandName !== "unban") return
const focusedOption = interaction.options.getFocused(true) const focusedOption = interaction.options.getFocused(true)
if (focusedOption.name !== "user") return if (focusedOption.name !== "user") return

View File

@@ -14,7 +14,19 @@ function loadAutocompleteEvents(client) {
const autocomplete = require(filePath) const autocomplete = require(filePath)
if ("name" in autocomplete && "execute" in autocomplete && autocomplete.type === "autocomplete") { 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 { } else {
console.log(`[WARNING] The autocomplete at ${filePath} is missing a required "name", "execute" or "type" property.`) console.log(`[WARNING] The autocomplete at ${filePath} is missing a required "name", "execute" or "type" property.`)
} }