Skip to content

Commit 58a4ada

Browse files
authored
Add interaction create event (#11)
* Create interaction create event * Add comments * Forgot try catch
1 parent a3d2054 commit 58a4ada

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/commands/commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type AppCommands = {
88
};
99
export type AppCommand = {
1010
data: SlashCommandBuilder;
11-
execute: (data: AppCommandOptions) => void;
11+
execute: (data: AppCommandOptions) => Promise<void>;
1212
};
1313
export type AppCommandOptions = {
1414
interaction: CommandInteraction;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { CacheType, Interaction } from 'discord.js';
2+
import { AppCommands } from '../../commands/commands';
3+
import { EventModule } from '../events';
4+
5+
export default function ({ app, appCommands }: EventModule) {
6+
app.on('interactionCreate', async (interaction: Interaction<CacheType>) => {
7+
try {
8+
if (!interaction.inGuild() || !appCommands) return;
9+
10+
if (interaction.isCommand()) {
11+
const { commandName } = interaction;
12+
const command = appCommands[commandName as keyof AppCommands];
13+
command && (await command.execute({ interaction, app }));
14+
}
15+
//Maybe add buttons, selections and modal handlers here eventually
16+
} catch (errors) {
17+
//TODO: Add error handling
18+
console.log(errors);
19+
}
20+
});
21+
}

0 commit comments

Comments
 (0)