Skip to content

Commit 7574746

Browse files
committed
refactor(commands):( use defaultexport to allow for command names with spaces in them
1 parent 951fbd1 commit 7574746

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

src/commands/index.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
1-
export { default as close } from "./util/close.js";
2-
export { default as reopen } from "./util/reopen.js";
1+
import type {
2+
SlashCommandBuilder,
3+
ChatInputCommandInteraction,
34

4-
export { default as walkthrough } from "./util/walkthrough.js";
5+
ContextMenuCommandBuilder,
6+
ContextMenuCommandInteraction,
7+
SlashCommandOptionsOnlyBuilder,
8+
} from "discord.js";
9+
10+
import { default as close } from "./util/close.js";
11+
import { default as reopen } from "./util/reopen.js";
12+
import { default as walkthrough } from "./util/walkthrough.js";
13+
14+
type AnyCommandBuilder = SlashCommandBuilder | SlashCommandOptionsOnlyBuilder | ContextMenuCommandBuilder;
15+
type AnyInteraction = ChatInputCommandInteraction | ContextMenuCommandInteraction;
16+
17+
const commandObject: { [key: string]: { data: AnyCommandBuilder, execute: (interaction: AnyInteraction) => unknown } } = {};
18+
19+
for (const command of [close, reopen, walkthrough]) {
20+
commandObject[command.data.name] = command;
21+
}
22+
23+
export default commandObject;

src/deploy-commands.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { config } from "@lib/config.js";
2-
import * as commands from "@commands/index.js";
2+
import { getClientIDFromToken } from "@lib/discord/users.js";
3+
4+
import commands from "@commands/index.js";
35

46
import { REST, Routes } from "discord.js";
57

68
// Construct and prepare an instance of the REST module
79
const rest = new REST().setToken(config.token);
810

9-
const commandData = Object.values(commands).map((command) => command.data);
11+
const commandData = Object.values(commands).map((command) => command.data.toJSON());
1012

1113
console.log(
1214
`Started refreshing ${commandData.length} application (/) commands.`,
@@ -15,7 +17,7 @@ console.log(
1517
// The put method is used to fully refresh all commands in the guild with the current set
1618
// biome-ignore lint/suspicious/noExplicitAny: TODO: need to figure out the proper type
1719
const data: any = await rest.put(
18-
Routes.applicationGuildCommands("1063886601165471814", config.serverId), // TODO: guess client ID from token
20+
Routes.applicationGuildCommands(getClientIDFromToken(config.token), config.serverId), // TODO: guess client ID from token
1921
{ body: commandData },
2022
);
2123

src/events/commands.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as commands from "@commands/index.js";
1+
import commands from "@commands/index.js";
22

33
import { type Client, Events } from "discord.js";
44

@@ -9,7 +9,7 @@ export default function registerEvents(client: Client) {
99

1010
if (!command) {
1111
console.error(
12-
`No command matching ${interaction.commandName} was found.`,
12+
`No command matching "${interaction.commandName}" was found.`,
1313
);
1414
return;
1515
}
@@ -32,6 +32,8 @@ export default function registerEvents(client: Client) {
3232
});
3333
}
3434
}
35+
} else if(interaction.isUserContextMenuCommand()) {
36+
3537
}
3638
});
3739
}

0 commit comments

Comments
 (0)