added proper modal handler and raidplan

This commit is contained in:
DeSqBlocki
2026-08-14 23:49:31 +02:00
parent 9e94e99874
commit dafa81e2a6
5 changed files with 1696 additions and 44 deletions
+214 -44
View File
@@ -1,97 +1,267 @@
const { Events, MessageFlags, Message } = require('discord.js')
const { mClient } = require('../index')
require('dotenv').config()
const {
Events,
MessageFlags
} = require("discord.js");
require("dotenv").config();
module.exports = {
name: Events.InteractionCreate,
once: false,
async execute(interaction) {
if (interaction.isChatInputCommand()) { commandHandler(interaction) }
if (interaction.isButton()) { buttonHandler(interaction) }
if (interaction.isMentionableSelectMenu()) { selectMenuHandler(interaction) }
if (interaction.isUserSelectMenu()) { selectMenuHandler(interaction) }
if (interaction.isModalSubmit()) { modalHandler(interaction) }
}
}
async function commandHandler(interaction) {
const command = interaction.client.commands.get(interaction.commandName);
if (!command) { return console.error(`No command matching ${interaction.commandName} was found.`) }
async execute(interaction) {
if (interaction.isAutocomplete()) {
return autocompleteHandler(interaction);
}
if (interaction.isChatInputCommand()) {
return commandHandler(interaction);
}
if (interaction.isButton()) {
return buttonHandler(interaction);
}
if (
interaction.isMentionableSelectMenu() ||
interaction.isUserSelectMenu()
) {
return selectMenuHandler(interaction);
}
if (interaction.isModalSubmit()) {
return modalHandler(interaction);
}
}
};
async function autocompleteHandler(interaction) {
const command =
interaction.client.commands.get(
interaction.commandName
);
if (!command) {
return console.error(
`No command matching ${interaction.commandName} was found.`
);
}
if (
typeof command.autocomplete !==
"function"
) {
return;
}
try {
await command.execute(interaction);
await command.autocomplete(
interaction
);
} catch (error) {
console.error(
`Autocomplete error for /${interaction.commandName}:`,
error
);
/*
* Autocomplete cannot use normal interaction.reply().
* If something failed, send an empty set so Discord
* stops waiting.
*/
try {
await interaction.respond([]);
} catch {
// Interaction may already be acknowledged or expired.
}
}
}
async function commandHandler(interaction) {
const command =
interaction.client.commands.get(
interaction.commandName
);
if (!command) {
return console.error(
`No command matching ${interaction.commandName} was found.`
);
}
try {
await command.execute(
interaction
);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
if (
interaction.replied ||
interaction.deferred
) {
await interaction.followUp({
content: 'There was an error while executing this command!',
flags: MessageFlags.Ephemeral
content:
"There was an error while executing this command!",
flags:
MessageFlags.Ephemeral
});
} else {
await interaction.reply({
content: 'There was an error while executing this command!',
flags: MessageFlags.Ephemeral
content:
"There was an error while executing this command!",
flags:
MessageFlags.Ephemeral
});
}
}
}
async function buttonHandler(interaction) {
const button = interaction.client.buttons.get(interaction.customId)
if (!button) { return console.error(`No button registered matching ${interaction.customId}.`) }
const button =
interaction.client.buttons.get(
interaction.customId
);
if (!button) {
return console.error(
`No button registered matching ${interaction.customId}.`
);
}
try {
await button.execute(interaction);
await button.execute(
interaction
);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
if (
interaction.replied ||
interaction.deferred
) {
await interaction.followUp({
content: 'There was an error while executing this command!',
flags: MessageFlags.Ephemeral
content:
"There was an error while executing this button!",
flags:
MessageFlags.Ephemeral
});
} else {
await interaction.reply({
content: 'There was an error while executing this command!',
flags: MessageFlags.Ephemeral
content:
"There was an error while executing this button!",
flags:
MessageFlags.Ephemeral
});
}
}
}
async function selectMenuHandler(interaction) {
const selectMenu = interaction.client.selectMenus.get(interaction.customId)
if (!selectMenu) { return console.error(`No Select Menu registered matching ${interaction.customId}.`) }
const selectMenu =
interaction.client.selectMenus.get(
interaction.customId
);
if (!selectMenu) {
return console.error(
`No Select Menu registered matching ${interaction.customId}.`
);
}
try {
await selectMenu.execute(interaction);
await selectMenu.execute(
interaction
);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
if (
interaction.replied ||
interaction.deferred
) {
await interaction.followUp({
content: 'There was an error while executing this command!',
flags: MessageFlags.Ephemeral
content:
"There was an error while executing this select menu!",
flags:
MessageFlags.Ephemeral
});
} else {
await interaction.reply({
content: 'There was an error while executing this command!',
flags: MessageFlags.Ephemeral
content:
"There was an error while executing this select menu!",
flags:
MessageFlags.Ephemeral
});
}
}
}
async function modalHandler(interaction) {
const modal = interaction.client.modals.get(interaction.customId);
if (!modal) { return console.error(`No Modal registered matching ${interaction.customId}.`); }
const baseCustomId =
interaction.customId.split(":")[0];
const modal =
interaction.client.modals.get(
baseCustomId
);
if (!modal) {
return console.error(
`No Modal registered matching ${interaction.customId}.`
);
}
try {
await modal.execute(interaction);
await modal.execute(
interaction
);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
if (
interaction.replied ||
interaction.deferred
) {
await interaction.followUp({
content: 'There was an error while executing this modal!',
flags: MessageFlags.Ephemeral
content:
"There was an error while executing this modal!",
flags:
MessageFlags.Ephemeral
});
} else {
await interaction.reply({
content: 'There was an error while executing this modal!',
flags: MessageFlags.Ephemeral
content:
"There was an error while executing this modal!",
flags:
MessageFlags.Ephemeral
});
}
}