-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
70 lines (58 loc) · 2.26 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
const fs = require('fs');
const { Client, CommandInteraction, Events, Collection, Partials, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');
const { InteractionType } = require("discord-api-types/v10");
const client = new Client({ intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent],
partials: [
Partials.Channel,
],
});
const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
const event = require(`./events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}
client.commands = new Collection();
const cmdPaths = require("./cmdPaths.js").data;
const commandFiles = [];
for (let i = 0; i < cmdPaths.length; i++) {
commandFiles[i] = fs.readdirSync(cmdPaths[i]).filter(file => file.endsWith(".js"));
for (let j = 0; j < commandFiles[i].length; j++) {
commandFiles[i][j] = cmdPaths[i] + "/" + commandFiles[i][j];
}
}
for (const fileArray of commandFiles) {
for (const file of fileArray) {
const command = require(`./${file}`);
client.commands.set(command.data.name, command);
if (command.akaNames != null && Array.isArray(command.akaNames) && command.akaNames.length > 0) {
for (let i = 0; i < command.akaNames.length; i++) {
client.commands.set(command.akaNames[i], command);
}
}
}
}
client.once('ready', () => {
console.log('Bot Ready!');});
client.on('interactionCreate', async interaction => {
if (interaction.type !== InteractionType.ApplicationCommand) return;
const command = 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);