Files
illegitimate-bot/src/events/autocomplete/unban.js
2023-12-11 13:41:49 +01:00

34 lines
1.1 KiB
JavaScript

module.exports = {
name: "unban",
description: "Unban a user from the server",
type: "autocomplete",
/** @param { import("discord.js").AutocompleteInteraction } interaction */
async execute(interaction) {
if (interaction.commandName !== "unban") return
const focusedOption = interaction.options.getFocused(true)
if (focusedOption.name !== "user") return
if (focusedOption.value === "") {
await interaction.respond([{
name: "Please start typing a username to unban",
value: "none"
}])
return
}
const bannedUsers = await interaction.guild.bans.fetch()
const filteredUsers = bannedUsers.filter((user) =>
user.user.username.toLowerCase().includes(focusedOption.value.toLowerCase())
)
const results = filteredUsers.map((user) => ({
name: user.user.username,
value: user.user.id,
}))
await interaction.respond(results.slice(0, 25)).catch((err) => { console.log(err) })
}
}