-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
55 lines (44 loc) · 1.67 KB
/
index.js
File metadata and controls
55 lines (44 loc) · 1.67 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
// Requrie stuff
const fs = require('fs');
const { Client, Collection, Intents } = require('discord.js');
require('dotenv').config();
const mongoose = require('mongoose');
// Tokesn and URLs and other constants
const { TOKEN, DB_URL } = process.env;
// Create discord client
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
// Load all commands in the commands folder
client.commands = new Collection();
const commandFiles = fs.readdirSync('./commands').filter((file) => file.endsWith('.js'));
commandFiles.forEach((file) => {
// eslint-disable-next-line import/no-dynamic-require
const command = require(`./commands/${file}`);
client.commands.set(command.data.name, command);
});
client.once('ready', () => {
console.log('Ready!');
});
client.on('interactionCreate', async (interaction) => {
if (interaction.isCommand()) {
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 });
}
} else if (interaction.isButton()) {
const command = client.commands.get(interaction.customId.split('.')[0]);
try {
await command.handleButton(interaction);
} catch (error) {
console.error(error);
await interaction.update({ content: 'There was an error while executing this command', components: [] });
}
}
});
mongoose.connect(DB_URL, () => {
console.log("Mongoose connected");
client.login(TOKEN);
});