-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
89 lines (72 loc) · 2.51 KB
/
index.js
File metadata and controls
89 lines (72 loc) · 2.51 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
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
const Discord = require("discord.js");
const fs = require("fs");
const client = new Discord.Client({
intents: Object.keys(Discord.IntentsBitField.Flags).map(key => Discord.IntentsBitField.Flags[key])
});
const config = require("./config.json");
client.config = config;
client.log = async function (type, message) {
const hook = new Discord.WebhookClient(client.config.logWebhook);
if (!client.user) {
client.user = {}
client.user.tag = "Unkown Bot"
client.user.id = ""
client.user.displayAvatarURL = function () {
return "https://i.imgur.com/jNz2Dwp.png"
}
}
let embed = new Discord.EmbedBuilder()
.setAuthor({name: `${client.user.tag} (${client.user.id})`, iconURL: client.user.displayAvatarURL()})
let logLineDetails = ((new Error().stack).split("at ")[2]).trim();
switch (type) {
case 'error' : {
embed.setTitle(`An error happend`)
.setColor('#ff0000')
.setDescription(message.toString())
.addFields([{name: `File :`, value: logLineDetails}])
console.error(message)
break;
}
case 'action' : {
embed.setColor('#00f7ff')
.setDescription(message.toString())
.addFields([{name: `File :`, value: logLineDetails}])
}
}
await hook.send({embeds: [embed.setTimestamp()]}).catch(console.error)
}
if (!client.config.allowedUsers.includes(client.config.owner)) {
client.config.allowedUsers.push(client.config.owner)
fs.writeFileSync("./config.json", JSON.stringify(client.config, null, 4), "utf-8")
}
client.commands = new Discord.Collection();
fs.readdir("./events/", (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
const event = require(`./events/${file}`);
let eventName = file.split(".")[0];
console.log(`Attempting to load event ${eventName}`);
try {
client.on(eventName, event.bind(null, client));
}
catch (e) {
client.log("error", e);
}
});
});
client.login(config.token).then(() => {}).catch(e => client.log("error", e));
process.on('unhandledRejection', error => {
client.log("error", error)
})
process.on('uncaughtException', error => {
client.log("error", error)
})
process.on('warning', error => {
client.log("error", error)
})
process.on('error', error => {
client.log("error", error)
})
process.on('exit', error => {
client.log("error", error)
})