forked from Late-Is-Cool/appel-for-discord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
90 lines (83 loc) · 3.06 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
require("module-alias/register");
require("dotenv").config();
const { Client, MessageEmbed, MessageAttachment, Collection } = require("discord.js");
const client = new Client({
intents: 1537,
});
const path = require("path");
const fs = require("fs");
// make a command handler with aliases
client.commands = new Collection();
client.aliases = new Collection();
const commandsFolder = fs
.readdirSync("./commands")
.filter((file) => file.endsWith(".js"));
for (file of commandsFolder) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`);
console.log(`Loaded ${client.commands.size} commands!`);
databaseChannel.messages.fetch({ limit: 1 }).then(async (messages) => {
if (messages.size == 0) {
// if there isnt a message, send the csv file
databaseChannel
.send({
content:
"**DATABASE**,\n\nDo not delete or unpin this message! If you do, the data will be cleared.",
files: [new MessageAttachment(csvFile, "data.csv")],
})
.then((message) => {
message.pin();
});
}
});
databaseChannel.messages
.fetchPinned({ limit: 1 })
.then(async (messages) => {
if (messages.size == 1) {
const message = messages.first();
message.edit({
files: [new MessageAttachment(csvFile, "data.csv")],
});
fs.watchFile(csvFile, (curr, prev) => {
// if the file is updated, edit the pinned message
message.edit({
files: [new MessageAttachment(csvFile, "data.csv")],
});
});
}
})
.catch((err) => console.log(err));
});
client.on("messageCreate", (message) => {
if (message.author.bot) return;
if (message.cleanContent.toLowerCase().startsWith(process.env.PREFIX)) {
const args = message.content
.slice(process.env.PREFIX.length)
.split(" ");
const commandName = args.shift().toLowerCase();
const command =
client.commands.get(commandName) ||
client.commands.find(
(cmd) => cmd.aliases && cmd.aliases.includes(commandName)
);
if (!command) return;
try {
command.callback(client, message, args);
} catch (e) {
message.channel.send({
embeds: [
new MessageEmbed()
.setTitle("Oops!")
.setColor("RED")
.setDescription(
`Apparently there was an error!\n\`\`\`${e}\`\`\``
),
],
});
}
}
});
client.login(process.env.TOKEN);