-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdiscord.js
104 lines (96 loc) · 2.89 KB
/
discord.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
101
102
103
104
const Discord = require("eris-additions")(require("eris"));
const { readdirSync } = require("fs");
const { sep } = require("path");
let config = require("./config");
const ms = require("ms");
const moment = require("moment");
const MongoClient = require('mongodb').MongoClient;
const client = new MongoClient(config.database, {useUnifiedTopology: true});
client.connect().then(connection => {
database = connection.db("TL-Events")
bot.database = database
})
const bot = new Discord.Client(config.discord.token, {
intents:5635,
compress: true,
guildSubscriptions:false,
messageLimit:0,
largeThreshold: 0,
disableEvents: {
'MESSAGE_DELETE':true,
'MESSAGE_DELETE_BULK':true,
'MESSAGE_UPDATE':true,
'USER_UPDATE':true,
'VOICE_SERVER_UPDATE':true
},
});
bot.config = config.discord;
// Creating command and aliases collection.
["commands", "aliases"].forEach((x) => (bot[x] = new Discord.Collection()));
const load = (dir = "./commands/") => {
readdirSync(dir).forEach((dirs) => {
// sub folder check
const commands = readdirSync(`${dir}${sep}${dirs}${sep}`).filter((files) =>
files.endsWith(".js")
);
// get all files in sub folder
for (const file of commands) {
// put all commands in collection
const pull = require(`${dir}/${dirs}/${file}`);
// check to see if command exists
if (
pull.info &&
typeof pull.info.name === "string" &&
typeof pull.info.category === "string"
) {
if (bot.commands.get(pull.info.name))
return console.warn(
`Two or more commands have the same name ${pull.info.name}.`
);
// get more info about command for help command
bot.commands.set(pull.info.name, pull);
console.log(`Loaded command ${pull.info.name}.`);
} else {
console.log(
`Error loading command in ${dir}${dirs}.${file} you have a missing info.name or info.name is not a string. or you have a missing info.category or info.category is not a string`
);
continue;
}
// command aliases
if (pull.info.aliases && typeof pull.info.aliases === "object") {
pull.info.aliases.forEach((alias) => {
// check for conflict with other commands
if (bot.aliases.get(alias))
return console.warn(
`Two commands or more commands have the same aliases ${alias}`
);
bot.aliases.set(alias, pull.info.name);
});
}
}
});
};
load();
bot
.on("error",console.error)
.on("warn", console.warn)
.on("ready", () => {
require("./discordEvents/ready").Run(bot);
})
.on("disconnect", () => {
console.warn("Disconnected!");
})
.on("reconnecting", () => {
console.warn(
`${moment(Date.now()).format("hh/mm A, DD/MM/YYYY")}: Reconnecting...`
);
})
.on("messageCreate", (message) => {
require('./discordEvents/message').Run(bot, message)
})
.on("interactionCreate",(interaction) => {
require('./discordEvents/interactionCreate').Run(bot,interaction)
})
setTimeout(async() => {
bot.connect()
}, 5*1000);