Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/test-bot/commandkit.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { tasks } from '@commandkit/tasks';
export default defineConfig({
plugins: [
i18n(),
legacy({ skipBuiltInValidations: true }),
// legacy({ skipBuiltInValidations: true }),
devtools(),
cache(),
ai(),
Expand Down
27 changes: 25 additions & 2 deletions apps/test-bot/src/app/commands/translate.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
import { MessageContextMenuCommand } from 'commandkit';
import {
ChatInputCommand,
MessageCommand,
MessageContextMenuCommand,
UserContextMenuCommand,
} from 'commandkit';
import { ApplicationCommandType, ContextMenuCommandBuilder } from 'discord.js';

export const command = new ContextMenuCommandBuilder()
.setName('translate')
.setType(ApplicationCommandType.Message);
.setType(ApplicationCommandType.User);

// export const command: CommandData = {
// name: 'translate',
// };

export const userContextMenu: UserContextMenuCommand = async ({
interaction,
}) => {
interaction.reply('test');
};

export const messageContextMenu: MessageContextMenuCommand = async ({
interaction,
}) => {
interaction.reply('test');
};

export const chatInput: ChatInputCommand = async ({ interaction }) => {
interaction.reply('test');
};

export const message: MessageCommand = async ({ message }) => {
message.reply('test');
};
7 changes: 3 additions & 4 deletions packages/commandkit/src/app/handlers/AppCommandHandler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
ApplicationCommandType,
AutocompleteInteraction,
Awaitable,
Collection,
Expand Down Expand Up @@ -783,7 +784,7 @@ export class AppCommandHandler {
*/
private async loadCommand(id: string, command: Command) {
try {
// Skip if path is null (directory-only command group)
// Skip if path is null (directory-only command group) - external plugins
if (command.path === null) {
this.loadedCommands.set(id, {
command,
Expand All @@ -796,8 +797,6 @@ export class AppCommandHandler {
data: {
command: {
name: command.name,
description: `${command.name} command`,
type: 1,
},
},
});
Expand Down Expand Up @@ -836,7 +835,7 @@ export class AppCommandHandler {
| string
| undefined;

// since `description` is optional in `CommandData` type, set a fallback description if none is provided
// since `CommandData.description` is optional, set a fallback description if none provided
if (!commandDescription && commandFileData.chatInput) {
commandDescription = 'No command description set.';
}
Expand Down
26 changes: 11 additions & 15 deletions packages/commandkit/src/app/register/CommandRegistrar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,41 +50,37 @@ export class CommandRegistrar {

const __metadata = cmd.metadata ?? cmd.data.metadata;

const collections: (CommandData & { __metadata?: CommandMetadata })[] = [
{
const collections: (CommandData & { __metadata?: CommandMetadata })[] =
[];

if (cmd.data.chatInput) {
collections.push({
...json,
type: ApplicationCommandType.ChatInput,
description: json.description ?? 'No command description set.',
__metadata,
},
];
});
}

// Handle context menu commands
if (
cmd.data.userContextMenu &&
json.type !== ApplicationCommandType.User
) {
if (cmd.data.userContextMenu) {
collections.push({
...json,
name: __metadata?.nameAliases?.user ?? json.name,
type: ApplicationCommandType.User,
options: undefined,
description_localizations: undefined,
// @ts-ignore
description: undefined,
// @ts-ignore
__metadata,
});
}

if (
cmd.data.messageContextMenu &&
json.type !== ApplicationCommandType.Message
) {
if (cmd.data.messageContextMenu) {
collections.push({
...json,
name: __metadata?.nameAliases?.message ?? json.name,
type: ApplicationCommandType.Message,
description_localizations: undefined,
// @ts-ignore
description: undefined,
options: undefined,
__metadata,
Expand Down