diff --git a/commands/user/.gitkeep b/commands/user/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/docs/custom-commands.md b/docs/custom-commands.md index 96633c54..1e7c0367 100644 --- a/docs/custom-commands.md +++ b/docs/custom-commands.md @@ -20,7 +20,7 @@ commands/ As you can see, each command is grouped into categories, which are represented by subdirectories. To create a new category, you can simply create a new directory inside of the `commands` directory, and to create a new command, you can create a new JS file under one of those subdirectories. !!! tip - The `message` category is special; commands in here act as right-click context menu message commands instead of "classic" or slash commands. + The `message` and `user` categories are special; instead of being registered as classic or slash commands, commands in these categories are registered as right-click context menu commands. Commands in the `message` category show when selecting messages, while commands in the `user` category show when selecting users. ## Command Structure It's recommended to use the `Command` class located in `classes/command.js` to create a new command in most cases. This class provides various parameters and fields that will likely be useful when creating a command. Here is a simple example of a working command file: diff --git a/events/interactionCreate.js b/events/interactionCreate.js index abf5c4cc..54955a70 100644 --- a/events/interactionCreate.js +++ b/events/interactionCreate.js @@ -1,6 +1,6 @@ import database from "../utils/database.js"; import logger from "../utils/logger.js"; -import { collectors, commands, messageCommands } from "../utils/collections.js"; +import { collectors, commands, messageCommands, userCommands } from "../utils/collections.js"; import { clean } from "../utils/misc.js"; import { upload } from "../utils/tempimages.js"; import { InteractionTypes } from "oceanic.js"; @@ -27,11 +27,8 @@ export default async (client, interaction) => { // check if command exists and if it's enabled const command = interaction.data.name; - let cmd = commands.get(command); - if (!cmd) { - cmd = messageCommands.get(command); - if (!cmd) return; - } + const cmd = commands.get(command) ?? messageCommands.get(command) ?? userCommands.get(command); + if (!cmd) return; try { await interaction.defer((cmd.ephemeral || interaction.data.options.getBoolean("ephemeral", false)) ? 64 : undefined); diff --git a/utils/collections.js b/utils/collections.js index 1b87bd79..7f55a5de 100644 --- a/utils/collections.js +++ b/utils/collections.js @@ -1,5 +1,6 @@ export const commands = new Map(); export const messageCommands = new Map(); +export const userCommands = new Map(); export const paths = new Map(); export const aliases = new Map(); export const info = new Map(); diff --git a/utils/handler.js b/utils/handler.js index 392df794..02b90878 100644 --- a/utils/handler.js +++ b/utils/handler.js @@ -1,4 +1,4 @@ -import { paths, commands, messageCommands, info, categories, aliases as _aliases } from "./collections.js"; +import { paths, commands, messageCommands, userCommands, info, categories, aliases as _aliases } from "./collections.js"; import { log } from "./logger.js"; import commandConfig from "../config/commands.json" with { type: "json" }; @@ -23,7 +23,7 @@ export async function load(client, command) { return; } - if (category === "message") { + if (category === "message" || category === "user") { const nameStringArray = commandName.split("-"); for (const index of nameStringArray.keys()) { nameStringArray[index] = nameStringArray[index].charAt(0).toUpperCase() + nameStringArray[index].slice(1); @@ -50,6 +50,9 @@ export async function load(client, command) { if (category === "message") { messageCommands.set(commandName, props); commandInfo.type = Constants.ApplicationCommandTypes.MESSAGE; + } else if (category === "user") { + userCommands.set(commandName, props); + commandInfo.type = Constants.ApplicationCommandTypes.USER; } else { commands.set(commandName, props); } @@ -95,7 +98,7 @@ function parseFlags(flags) { export function update() { const commandArray = []; const privateCommandArray = []; - const merged = new Map([...commands, ...messageCommands]); + const merged = new Map([...commands, ...messageCommands, ...userCommands]); for (const [name, command] of merged.entries()) { let cmdInfo = info.get(name); if (command.postInit) { @@ -114,7 +117,7 @@ export function update() { }; info.set(name, cmdInfo); } - if (cmdInfo?.type === Constants.ApplicationCommandTypes.MESSAGE) { + if (cmdInfo?.type === Constants.ApplicationCommandTypes.MESSAGE || cmdInfo?.type === Constants.ApplicationCommandTypes.USER) { (cmdInfo.adminOnly ? privateCommandArray : commandArray).push({ name: name, type: cmdInfo.type,