-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
90 lines (75 loc) · 2.66 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import path from "path";
import { readdirSync } from "fs";
import { token } from "./config";
import SlashCommandObject from "./models/SlashCommandObject";
import EventObject from "./models/EventObject";
import { Client, Collection, GatewayIntentBits } from "discord.js";
import ContextMenuObject from "./models/ContextMenuObject";
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildVoiceStates,
]
});
// Events
const eventFiles = readdirSync(path.join(__dirname, "/events/")).filter(file => file);
eventFiles.forEach(file => {
const event: EventObject = require(`./events/${file}`).default;
if (event.once) {
client.once(event.name, (...args: [any]) => event.execute(...args));
return;
}
client.on(event.name, (...args: [any]) => event.execute(...args));
})
// Commands & Context Menus
const commands = new Collection<string, SlashCommandObject>();
const contextMenus = new Collection<string, ContextMenuObject>();
const commandFiles = readdirSync(path.join(__dirname, "/commands/")).filter(file => file);
const contextMenuFiles = readdirSync(path.join(__dirname, "/context_menus/")).filter(file => file);
commandFiles.forEach(file => {
const command: SlashCommandObject = require(`./commands/${file}`).default;
commands.set(command.data.name, command);
});
contextMenuFiles.forEach(file => {
const contextMenu: ContextMenuObject = require(`./context_menus/${file}`).default;
contextMenus.set(contextMenu.data.name, contextMenu);
});
client.on("interactionCreate", async interaction => {
if (interaction.isCommand()) {
const command = commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({
content: "An error occured while executing this command", ephemeral: true
});
}
}
if (interaction.isUserContextMenuCommand()) {
const contextMenu = contextMenus.get(interaction.commandName);
if (!contextMenu) return;
try {
await contextMenu.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({
content: "An error occured while executing this interaction", ephemeral: true
});
}
}
if (interaction.isModalSubmit()) {
const modalHandler = require(`./events/modalHandle`).default;
try {
await modalHandler.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({
content: "An error occured while executing this interaction", ephemeral: true
});
}
}
})
client.login(token);