Merge branch 'dev' into 'main'
Updated file structure See merge request illegitimate/illegitimate-bot!127
This commit is contained in:
@@ -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.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
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const { InteractionType, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require("discord.js")
|
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require("discord.js")
|
||||||
const { color } = require("../../../config/options.json")
|
const { color } = require("../../../config/options.json")
|
||||||
const guildapp = require("../../schemas/guildAppSchema.js")
|
const guildapp = require("../../schemas/guildAppSchema.js")
|
||||||
|
|
||||||
@@ -10,10 +10,6 @@ module.exports = {
|
|||||||
/** @param { import('discord.js').ModalSubmitInteraction } interaction */
|
/** @param { import('discord.js').ModalSubmitInteraction } interaction */
|
||||||
|
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
|
|
||||||
if (interaction.type !== InteractionType.ModalSubmit) return
|
|
||||||
if (interaction.customId !== "denyreasonbox") return
|
|
||||||
|
|
||||||
interaction.deferReply()
|
interaction.deferReply()
|
||||||
|
|
||||||
const guild = interaction.guild
|
const guild = interaction.guild
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const { InteractionType, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require("discord.js")
|
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require("discord.js")
|
||||||
const { color } = require("../../../config/options.json")
|
const { color } = require("../../../config/options.json")
|
||||||
const staffapp = require("../../schemas/staffAppSchema.js")
|
const staffapp = require("../../schemas/staffAppSchema.js")
|
||||||
|
|
||||||
@@ -10,10 +10,6 @@ module.exports = {
|
|||||||
/** @param { import('discord.js').ModalSubmitInteraction } interaction */
|
/** @param { import('discord.js').ModalSubmitInteraction } interaction */
|
||||||
|
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
|
|
||||||
if (interaction.type !== InteractionType.ModalSubmit) return
|
|
||||||
if (interaction.customId !== "staffdenyreasonbox") return
|
|
||||||
|
|
||||||
interaction.deferReply()
|
interaction.deferReply()
|
||||||
|
|
||||||
const guild = interaction.guild
|
const guild = interaction.guild
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
const { InteractionType } = require("discord.js")
|
|
||||||
const { getUUID, getPlayer, getGuild, getHeadURL } = require("../../utils/utils.js")
|
const { getUUID, getPlayer, getGuild, getHeadURL } = require("../../utils/utils.js")
|
||||||
const { color, hypixelGuildID, devMessage } = require("../../../config/options.json")
|
const { color, hypixelGuildID, devMessage } = require("../../../config/options.json")
|
||||||
const verify = require("../../schemas/verifySchema.js")
|
const verify = require("../../schemas/verifySchema.js")
|
||||||
@@ -12,7 +11,6 @@ module.exports = {
|
|||||||
|
|
||||||
/** @param { import('discord.js').ModalSubmitInteraction } interaction */
|
/** @param { import('discord.js').ModalSubmitInteraction } interaction */
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
if (interaction.type !== InteractionType.ModalSubmit) return
|
|
||||||
await interaction.deferReply({ ephemeral: true })
|
await interaction.deferReply({ ephemeral: true })
|
||||||
|
|
||||||
const user1 = interaction.user
|
const user1 = interaction.user
|
||||||
|
|||||||
18
src/index.js
18
src/index.js
@@ -1,11 +1,13 @@
|
|||||||
const { Client, GatewayIntentBits, Partials, Collection } = require("discord.js")
|
const { Client, GatewayIntentBits, Partials } = require("discord.js")
|
||||||
const { loadSlashCommandsEvents, loadContextMenuEvents, loadModalEvents, loadButtonEvents, loadEvents, loadAutocompleteEvents } = require("./utils/eventHandler.js")
|
|
||||||
const { autoDeployCommands } = require("./utils/autodeploy.js")
|
const { autoDeployCommands } = require("./utils/autodeploy.js")
|
||||||
|
const { loadAllEvents } = require("./utils/loadEvents.js")
|
||||||
const { init } = require("./utils/init.js")
|
const { init } = require("./utils/init.js")
|
||||||
require("dotenv").config()
|
require("dotenv").config()
|
||||||
const mongoURI = process.env.MONGOURI
|
const mongoURI = process.env.MONGOURI
|
||||||
const { connect } = require("mongoose")
|
const { connect } = require("mongoose")
|
||||||
|
|
||||||
|
init()
|
||||||
|
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
intents: [
|
intents: [
|
||||||
GatewayIntentBits.Guilds,
|
GatewayIntentBits.Guilds,
|
||||||
@@ -23,17 +25,7 @@ const client = new Client({
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
client.commands = new Collection()
|
loadAllEvents(client)
|
||||||
client.events = new Collection()
|
|
||||||
client.modals = new Collection()
|
|
||||||
|
|
||||||
init()
|
|
||||||
loadSlashCommandsEvents(client)
|
|
||||||
loadAutocompleteEvents(client)
|
|
||||||
loadContextMenuEvents(client)
|
|
||||||
loadButtonEvents(client)
|
|
||||||
loadModalEvents(client)
|
|
||||||
loadEvents(client)
|
|
||||||
|
|
||||||
let token = ""
|
let token = ""
|
||||||
if (process.env.NODE_ENV === "dev") {
|
if (process.env.NODE_ENV === "dev") {
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
const { Events } = require("discord.js")
|
const { Events, Collection } = require("discord.js")
|
||||||
const path = require("path")
|
const path = require("path")
|
||||||
const fs = require("fs")
|
const fs = require("fs")
|
||||||
|
|
||||||
/** @param { import('discord.js').Client } client */
|
/** @param { import('discord.js').Client } client */
|
||||||
|
|
||||||
function loadAutocompleteEvents(client) {
|
function loadAutocompleteEvents(client) {
|
||||||
|
client.autocomplete = new Collection()
|
||||||
|
|
||||||
const autocompletePath = path.join(__dirname, "..", "..", "events", "autocomplete")
|
const autocompletePath = path.join(__dirname, "..", "..", "events", "autocomplete")
|
||||||
const autocompleteFiles = fs.readdirSync(autocompletePath).filter(file => file.endsWith(".js"))
|
const autocompleteFiles = fs.readdirSync(autocompletePath).filter(file => file.endsWith(".js"))
|
||||||
|
|
||||||
@@ -14,22 +16,31 @@ 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, async interaction => {
|
client.autocomplete.set(autocomplete.name, autocomplete)
|
||||||
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.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
client.on(Events.InteractionCreate, async interaction => {
|
||||||
|
if (!interaction.isAutocomplete()) return
|
||||||
|
|
||||||
|
const autocomplete = interaction.client.autocomplete.get(interaction.commandName)
|
||||||
|
|
||||||
|
if (!autocomplete) {
|
||||||
|
console.error(`No autocomplete matching ${interaction.commandName} was found.`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await autocomplete.execute(interaction, client)
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
await interaction.respond({
|
||||||
|
content: "There was an error while executing this autocomplete!",
|
||||||
|
ephemeral: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
const { Events } = require("discord.js")
|
const { Events, Collection } = require("discord.js")
|
||||||
const path = require("path")
|
const path = require("path")
|
||||||
const fs = require("fs")
|
const fs = require("fs")
|
||||||
|
|
||||||
/** @param { import('discord.js').Client } client */
|
/** @param { import('discord.js').Client } client */
|
||||||
|
|
||||||
function loadButtonEvents(client) {
|
function loadButtonEvents(client) {
|
||||||
|
client.buttons = new Collection()
|
||||||
|
|
||||||
const btnPath = path.join(__dirname, "..", "..", "events", "buttons")
|
const btnPath = path.join(__dirname, "..", "..", "events", "buttons")
|
||||||
const btnFiles = fs.readdirSync(btnPath).filter(file => file.endsWith(".js"))
|
const btnFiles = fs.readdirSync(btnPath).filter(file => file.endsWith(".js"))
|
||||||
|
|
||||||
@@ -14,28 +16,28 @@ function loadButtonEvents(client) {
|
|||||||
const btn = require(filePath)
|
const btn = require(filePath)
|
||||||
|
|
||||||
if ("name" in btn && "execute" in btn && btn.type === "button") {
|
if ("name" in btn && "execute" in btn && btn.type === "button") {
|
||||||
client.events.set(btn.name, btn)
|
client.buttons.set(btn.name, btn)
|
||||||
} else {
|
} else {
|
||||||
console.log(`[WARNING] The button at ${filePath} is missing a required "name", "execute" or "type" property.`)
|
console.log(`[WARNING] The button at ${filePath} is missing a required "name", "execute" or "type" property.`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
client.on(Events.InteractionCreate, async event => {
|
client.on(Events.InteractionCreate, async interaction => {
|
||||||
if (!event.isButton())
|
if (!interaction.isButton())
|
||||||
return
|
return
|
||||||
|
|
||||||
const event2 = event.client.events.get(event.customId)
|
const button = interaction.client.buttons.get(interaction.customId)
|
||||||
|
|
||||||
if (!event2) {
|
if (!button) {
|
||||||
console.error(`No event matching ${event.customId} was found.`)
|
console.error(`No event matching ${interaction.customId} was found.`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await event2.execute(event)
|
await button.execute(interaction)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
await event.reply({
|
await interaction.reply({
|
||||||
content: "There was an error while executing this event!",
|
content: "There was an error while executing this event!",
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
const { Events } = require("discord.js")
|
const { Events, Collection } = require("discord.js")
|
||||||
const path = require("path")
|
const path = require("path")
|
||||||
const fs = require("fs")
|
const fs = require("fs")
|
||||||
|
|
||||||
/** @param { import('discord.js').Client } client */
|
/** @param { import('discord.js').Client } client */
|
||||||
|
|
||||||
function loadSlashCommandsEvents(client) {
|
function loadSlashCommandsEvents(client) {
|
||||||
|
client.commands = new Collection()
|
||||||
|
|
||||||
const cmdPath = path.join(__dirname, "..", "..", "commands")
|
const cmdPath = path.join(__dirname, "..", "..", "commands")
|
||||||
const cmdFiles = fs.readdirSync(cmdPath).filter(file => file.endsWith(".js"))
|
const cmdFiles = fs.readdirSync(cmdPath).filter(file => file.endsWith(".js"))
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
const { Events } = require("discord.js")
|
const { Events, Collection } = require("discord.js")
|
||||||
const path = require("path")
|
const path = require("path")
|
||||||
const fs = require("fs")
|
const fs = require("fs")
|
||||||
|
|
||||||
/** @param { import('discord.js').Client } client */
|
/** @param { import('discord.js').Client } client */
|
||||||
|
|
||||||
function loadModalEvents(client) {
|
function loadModalEvents(client) {
|
||||||
|
client.modals = new Collection()
|
||||||
|
|
||||||
const modalPath = path.join(__dirname, "..", "..", "events", "modals")
|
const modalPath = path.join(__dirname, "..", "..", "events", "modals")
|
||||||
const modalFiles = fs.readdirSync(modalPath).filter(file => file.endsWith(".js"))
|
const modalFiles = fs.readdirSync(modalPath).filter(file => file.endsWith(".js"))
|
||||||
|
|
||||||
@@ -14,11 +16,33 @@ function loadModalEvents(client) {
|
|||||||
const modal = require(filePath)
|
const modal = require(filePath)
|
||||||
|
|
||||||
if ("name" in modal && "execute" in modal && modal.type === "modal") {
|
if ("name" in modal && "execute" in modal && modal.type === "modal") {
|
||||||
client.on(Events.InteractionCreate, modal.execute)
|
client.modals.set(modal.name, modal)
|
||||||
} else {
|
} else {
|
||||||
console.log(`[WARNING] The modal at ${filePath} is missing a required "name", "execute" or "type" property.`)
|
console.log(`[WARNING] The modal at ${filePath} is missing a required "name", "execute" or "type" property.`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
client.on(Events.InteractionCreate, async interaction => {
|
||||||
|
if (!interaction.isModalSubmit())
|
||||||
|
return
|
||||||
|
|
||||||
|
const modal = interaction.client.modals.get(interaction.customId)
|
||||||
|
|
||||||
|
if (!modal) {
|
||||||
|
console.error(`No modal matching ${interaction.customId} was found.`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await modal.execute(interaction)
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
await interaction.reply({
|
||||||
|
content: "There was an error while executing this modal!",
|
||||||
|
ephemeral: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { loadModalEvents }
|
module.exports = { loadModalEvents }
|
||||||
|
|||||||
12
src/utils/loadEvents.js
Normal file
12
src/utils/loadEvents.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
const { loadSlashCommandsEvents, loadContextMenuEvents, loadModalEvents, loadButtonEvents, loadEvents, loadAutocompleteEvents } = require("./eventHandler.js")
|
||||||
|
|
||||||
|
function loadAllEvents(client) {
|
||||||
|
loadSlashCommandsEvents(client)
|
||||||
|
loadAutocompleteEvents(client)
|
||||||
|
loadContextMenuEvents(client)
|
||||||
|
loadButtonEvents(client)
|
||||||
|
loadModalEvents(client)
|
||||||
|
loadEvents(client)
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { loadAllEvents }
|
||||||
Reference in New Issue
Block a user