-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
100 lines (93 loc) · 2.84 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
91
92
93
94
95
96
97
98
99
100
const { GatewayIntentBits, REST, Routes } = require("discord.js");
const prompt = require("prompt-sync")(),
fs = require("fs"),
discordjs = require("discord.js");
var settings = JSON.parse(fs.readFileSync("settings.json"));
process.on("uncaughtException", (error, orgi) => {
let ts = Date.now();
let date_ob = new Date(ts);
let date = date_ob.getDate();
let month = date_ob.getMonth() + 1;
let year = date_ob.getFullYear();
let hour = date_ob.getHours();
let min = date_ob.getMinutes();
let sec = date_ob.getSeconds();
fs.appendFileSync(
"log",
`[ERROR] [${year}/${month}/${date} | ${hour}:${min}:${sec}] An error has occured: \n` +
error +
`\n(origin): ` +
orgi +
"\n"
);
});
const bot = new discordjs.Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMembers,
],
});
bot.commands = new discordjs.Collection();
const commands = [];
fs.readdirSync("./commands").forEach(async (file) => {
const command = require(`./commands/${file}`);
commands.push(command.data.toJSON());
bot.commands.set(command.data.name, command);
});
fs.readdirSync("./events").forEach(async (file) => {
const event = require(`./events/${file}`);
if (event.once) {
bot.once(event.name, (...args) => event.execute(...args));
} else {
bot.on(event.name, (...args) => event.execute(...args));
}
});
const rest = new REST({ version: "10" }).setToken(settings["bot"]["token"]);
(async () => {
try {
// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationGuildCommands(
settings.bot.clientID,
settings.bot.guildID
),
{ body: commands }
);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
})();
bot.on(discordjs.Events.InteractionCreate, async (interaction) => {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
return;
}
try {
await command.run(bot, interaction);
} catch (error) {
console.error(error);
let ts = Date.now();
let date_ob = new Date(ts);
let date = date_ob.getDate();
let month = date_ob.getMonth() + 1;
let year = date_ob.getFullYear();
let hour = date_ob.getHours();
let min = date_ob.getMinutes();
let sec = date_ob.getSeconds();
fs.appendFileSync(
"log",
`[ERROR] [${year}/${month}/${date} | ${hour}:${min}:${sec}] An error has occured: \n` +
error
);
await interaction.reply({
content: "There was an error while executing this command!",
ephemeral: true,
});
}
});
bot.login(settings.bot.token);