forked from Mic-R/BTEG-Teamtool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
132 lines (122 loc) · 3.79 KB
/
index.js
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
const Discord = require("discord.js");
require("dotenv").config();
const schedule = require("./schedules/schedule");
const fs = require("node:fs");
const path = require("node:path");
const client = new Discord.Client({
intents: [
Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.MessageContent,
Discord.GatewayIntentBits.GuildMembers
],
});
client.options.fetchAllMembers = true;
client.options.fetchTimeout = 60000;
client.on("ready", () => {
console.info("Ready! Logged in as " + client.user.username);
schedule(client);
//command handling
client.commands = new Discord.Collection();
const commandsPath = path.join(__dirname, "commands");
const commandFiles = fs
.readdirSync(commandsPath)
.filter((file) => file.endsWith(".js"));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ("data" in command && "execute" in command) {
client.commands.set(command.data.name, command);
client.application.commands
.create(command.data.toJSON())
.then(() => console.log("Registered /" + command.data.name))
.catch((e) => console.warn(e.message));
} else {
console.warn(
`The command at ${filePath} is missing a required "data" or "execute" property.`
);
}
}
//buttons handling
client.buttons = new Discord.Collection();
const buttonFiles = fs
.readdirSync(`./buttons/`)
.filter((file) => file.endsWith(".js"));
for (const file of buttonFiles) {
const button = require(`./buttons/${file}`);
if ("data" in button && "execute" in button) {
client.buttons.set(button.data.name, button);
} else {
console.warn(
`The command at ${`./buttons/${file}`} is missing a required "data" or "execute" property.`
);
}
}
//modals handling
client.modals = new Discord.Collection();
const modalFiles = fs
.readdirSync(`./modals/`)
.filter((file) => file.endsWith(".js"));
for (const file of modalFiles) {
const modal = require(`./modals/${file}`);
if ("data" in modal && "execute" in modal) {
client.modals.set(modal.data.data.custom_id, modal);
} else {
console.warn(
`The modal at ${`./modals/${file}`} is missing a required "data" or "execute" property.`
);
}
}
});
client.on(Discord.Events.InteractionCreate, async (interaction) => {
if (interaction.isCommand()) {
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(
`No command matching ${interaction.commandName} was found.`
);
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,
});
}
}
if (interaction.isButton()) {
const button = client.buttons.get(interaction.customId);
if (!button) {
console.error(`No button matching ${interaction.customId} was found.`);
return;
}
try {
await button.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({
content: "There was an error while executing this button!",
ephemeral: true,
});
}
}
if (interaction.isModalSubmit()) {
const modal = client.modals.get(interaction.customId);
if (!modal) {
console.error(`No modal matching ${interaction.customId} was found.`);
return;
}
try {
await modal.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({
content: "There was an error while executing this modal!",
ephemeral: true,
});
}
}
});
client.login(process.env.TOKEN);