-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
32 lines (24 loc) · 920 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { Interaction, Intents, Client, Collection } from "discord.js";
import { token } from './config.json'
import { ClientWithCommands, Command } from "./types/client";
import { getCommandsAsMap } from "./utils/commandsFile";
async function main() {
const client : ClientWithCommands = new Client({ intents: [Intents.FLAGS.GUILDS] });
client.commands = await getCommandsAsMap();
client.once('ready', () => {
console.log('=== Bot is ready ===');
});
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
const command : Command | undefined = client.commands?.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
});
client.login(token);
}
main();