Move context menus to their own folder
This commit is contained in:
@@ -2,9 +2,9 @@ import { ApplicationIntegrationType, Client, InteractionContextType, PermissionF
|
|||||||
import { channelIsInStaffCategory, handleWhoIsInteraction } from '../utils';
|
import { channelIsInStaffCategory, handleWhoIsInteraction } from '../utils';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'whois-context',
|
name: 'Whois',
|
||||||
data: new ContextMenuCommandBuilder()
|
data: new ContextMenuCommandBuilder()
|
||||||
.setName('whois-context')
|
.setName('Whois')
|
||||||
.setIntegrationTypes(ApplicationIntegrationType.GuildInstall)
|
.setIntegrationTypes(ApplicationIntegrationType.GuildInstall)
|
||||||
.setContexts(InteractionContextType.Guild)
|
.setContexts(InteractionContextType.Guild)
|
||||||
.setDefaultMemberPermissions(PermissionFlagsBits.BanMembers)
|
.setDefaultMemberPermissions(PermissionFlagsBits.BanMembers)
|
||||||
+12
-2
@@ -31,11 +31,13 @@ const client = new DiscordClient({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const commands: Handler[] = [];
|
const commands: Handler[] = [];
|
||||||
|
const contextMenus: Handler[] = [];
|
||||||
const buttons: Handler[] = [];
|
const buttons: Handler[] = [];
|
||||||
const modals: Handler[] = [];
|
const modals: Handler[] = [];
|
||||||
const menus: Handler[] = [];
|
const menus: Handler[] = [];
|
||||||
|
|
||||||
loadHandlersFrom('commands', commands);
|
loadHandlersFrom('commands', commands);
|
||||||
|
loadHandlersFrom('context-menus', contextMenus);
|
||||||
loadHandlersFrom('buttons', buttons);
|
loadHandlersFrom('buttons', buttons);
|
||||||
loadHandlersFrom('modals', modals);
|
loadHandlersFrom('modals', modals);
|
||||||
loadHandlersFrom('menus', menus);
|
loadHandlersFrom('menus', menus);
|
||||||
@@ -59,14 +61,22 @@ client.on('interactionCreate', async (interaction) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (interaction.isChatInputCommand() || interaction.isContextMenuCommand()) {
|
if (interaction.isChatInputCommand()) {
|
||||||
// Handle chat and context menu commands.
|
// Handle chat
|
||||||
for (const command of commands) {
|
for (const command of commands) {
|
||||||
if (interaction.commandName == command.name) {
|
if (interaction.commandName == command.name) {
|
||||||
command.handler(client, interaction);
|
command.handler(client, interaction);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (interaction.isContextMenuCommand()) {
|
||||||
|
// Handle context menu commands.
|
||||||
|
for (const command of contextMenus) {
|
||||||
|
if (interaction.commandName == command.name) {
|
||||||
|
command.handler(client, interaction);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (interaction.isAutocomplete()) {
|
} else if (interaction.isAutocomplete()) {
|
||||||
// Handle autocomplete requests.
|
// Handle autocomplete requests.
|
||||||
for (const command of commands) {
|
for (const command of commands) {
|
||||||
|
|||||||
@@ -13,11 +13,22 @@ export async function refreshCommands(client: Client) {
|
|||||||
try {
|
try {
|
||||||
const commands: RESTPostAPIApplicationCommandsJSONBody[] = [];
|
const commands: RESTPostAPIApplicationCommandsJSONBody[] = [];
|
||||||
const guildCommands: { [id: string]: RESTPostAPIApplicationCommandsJSONBody[] } = {};
|
const guildCommands: { [id: string]: RESTPostAPIApplicationCommandsJSONBody[] } = {};
|
||||||
const commandFiles = fs.readdirSync(`${ROOT_DIR}/commands`).filter(file => file.endsWith('.js') || file.endsWith('.ts'));
|
const commandFiles = {
|
||||||
|
commands: fs.readdirSync(`${ROOT_DIR}/commands`).filter(file => file.endsWith('.js') || file.endsWith('.ts')),
|
||||||
|
'context-menus': fs.readdirSync(`${ROOT_DIR}/context-menus`).filter(file => file.endsWith('.js') || file.endsWith('.ts')),
|
||||||
|
};
|
||||||
|
|
||||||
for (const file of commandFiles) {
|
for (const [folderName, files] of Object.entries(commandFiles)) {
|
||||||
|
for (const file of files) {
|
||||||
|
const p = `${ROOT_DIR}/${folderName}/${file}`;
|
||||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||||
const command: Command = require(`${ROOT_DIR}/commands/${file}`).default;
|
const command: Command = require(p).default;
|
||||||
|
|
||||||
|
if (!command) {
|
||||||
|
console.warn(`File at ${p} has no export. Skipping registering.`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
let data: RESTPostAPIApplicationCommandsJSONBody;
|
let data: RESTPostAPIApplicationCommandsJSONBody;
|
||||||
if (typeof (command.data) == 'function') {
|
if (typeof (command.data) == 'function') {
|
||||||
data = (await command.data(client)).toJSON();
|
data = (await command.data(client)).toJSON();
|
||||||
@@ -34,6 +45,8 @@ export async function refreshCommands(client: Client) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
console.log('Started refreshing application (/) commands.');
|
console.log('Started refreshing application (/) commands.');
|
||||||
|
|
||||||
console.log('Global commands: ' + commands.length);
|
console.log('Global commands: ' + commands.length);
|
||||||
|
|||||||
Reference in New Issue
Block a user