-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
146 lines (135 loc) · 3.9 KB
/
index.js
File metadata and controls
146 lines (135 loc) · 3.9 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
const path = require("path");
const fs = require("fs");
const discord = require("discord.js");
const { PrismaClient } = require("@prisma/client");
require("dotenv").config();
const client = new discord.Client({
intents: new discord.IntentsBitField(33283),
});
const prisma = new PrismaClient();
const api = require("./api/api.js");
const commands = [];
const buttons = [];
const modals = [];
client.on("ready", () => {
console.log(new Date().toLocaleString(), "Ready!");
});
const eventsPath = path.join(__dirname, "event");
const eventFiles = fs.readdirSync(eventsPath);
for (const file of eventFiles) {
const filePath = path.join(eventsPath, file);
const event = require(filePath);
if (event.name !== "ready" && event.name !== "interactionCreate") {
if (event.once) {
console.log(
new Date().toLocaleString(),
`Event registriert: ${event.name}`
);
client.once(event.name, (...args) => event.execute(...args));
} else {
console.log(
new Date().toLocaleString(),
`Event registriert: ${event.name}`
);
client.on(event.name, (...args) => event.execute(...args));
}
}
}
client.once("ready", async () => {
//load command from command handler dir
// client.application.commands.set([]);
const commandFiles = fs
.readdirSync("./commands")
.filter((file) => file.endsWith(".js"));
for (const file of commandFiles) {
let data = require(`./commands/${file}`);
commands.push(data);
client.application.commands
.create(data.command)
.then(() =>
console.log(
new Date().toLocaleString(),
`Command registriert: /${data.command.name}`
)
)
.catch(console.error);
}
const scheduleFiles = fs
.readdirSync("./schedule")
.filter((file) => file.endsWith(".js"));
for (const file of scheduleFiles) {
let data = require(`./schedule/${file}`);
console.log(
new Date().toLocaleString(),
`Schedule registriert: ${file} (${data.time}ms)`
);
setInterval(() => {
data.run(client, prisma);
}, data.time);
}
const buttonFiles = fs
.readdirSync("./buttons")
.filter((file) => file.endsWith(".js"));
for (const file of buttonFiles) {
let data = require(`./buttons/${file}`);
buttons.push(data);
}
const modalFiles = fs
.readdirSync("./modals")
.filter((file) => file.endsWith(".js"));
for (const file of modalFiles) {
let data = require(`./modals/${file}`);
modals.push(data);
}
await api.start();
});
client.on("interactionCreate", async (interaction) => {
if (interaction.isCommand()) {
const command = commands.find(
(command) => command.command.name === interaction.commandName
);
if (!command) return;
try {
await command.run(client, interaction, prisma);
} catch (error) {
console.error(error);
await interaction.reply({
content: "Beim Registrieren dieses Befehls ist ein Fehler aufgetreten!",
ephemeral: true,
});
}
}
if (interaction.isButton()) {
const button = buttons.find((button) =>
interaction.customId.startsWith(button.button.name)
);
if (!button) return;
try {
await button.run(client, interaction, prisma);
} catch (error) {
console.error(error);
await interaction.reply({
content:
"Beim Ausführen dieser Schaltfläche ist ein Fehler aufgetreten! ",
ephemeral: true,
});
}
}
//is modal
if (interaction.isModalSubmit()) {
const modal = modals.find((modal) =>
interaction.customId.startsWith(modal.modal.name)
);
if (!modal) return;
try {
await modal.run(client, interaction, prisma);
} catch (error) {
console.error(error);
await interaction.reply({
content: "Beim Ausführen dieses Modals ist ein Fehler aufgetreten! ",
ephemeral: true,
});
}
}
});
client.login(process.env.BOT_TOKEN);