-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
48 lines (39 loc) · 1.69 KB
/
index.js
File metadata and controls
48 lines (39 loc) · 1.69 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
const { Client, Collection, Intents } = require('discord.js');
const monk = require("monk");
const fs = require('fs');
const { createTicket, closeTicket } = require('./ticket.js');
const { token, mongo } = require('./config.json');
const db = monk(mongo);
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
client.commands = new Collection();
client.cooldowns = 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(command.data.name, command);
}
client.once('ready', () => {
client.user.setPresence({ activities: [{ name: "you 💻", type: 2 }] });
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, db);
} catch (error) {
console.error(error);
return interaction.reply({ content: "There was an error while executing this command!", ephemeral: true });
}
} else if (interaction.isButton()) {
if (interaction.customId.includes("close")) {
let ticketData = await db.get("tickets").findOne({ id: interaction.customId.split("-")[2] });
if (ticketData) return closeTicket(interaction, ticketData, db, client);
} else {
let buttonData = await db.get("tickets").findOne({ id: interaction.customId });
if (buttonData) return createTicket(interaction, buttonData, client);
}
}
});
client.login(token);