forked from drB-dotjpg/IPL-Stream-Highlight-Creator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (38 loc) · 1.36 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
//require necessary js classes
const fs = require('fs');
const { Client, Intents, Collection } = require('discord.js');
const { token } = require("./config.json");
console.log("Logging into bot...\nDon't forget to run deploy-commands.js if you made changes to any config files!");
//create a new client instance
const client = new Client({
intents: [Intents.FLAGS.GUILDS]
});
//get all the command files and load them
client.commands = new Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(file.replace(".js", ""), command);
}
//run this when this client is ready
client.once('ready', () => {
console.log("Logged in! Awaiting commands.");
});
//runs whenever there is an interaction (eg. a command is run)
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
let command;
if (interaction.commandName.includes("graphic-")){
command = client.commands.get("graphic");
} else {
command = client.commands.get(interaction.commandName);
}
if (!command) return;
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'I had trouble executing that command!', ephemeral: true });
}
});
client.login(token);