-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
94 lines (92 loc) · 2.99 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
// Import config and export
const config = require('./config');
const mongoose = require('mongoose');
const colors = require('colors');
// Connect to mongoDB
try {
mongoose.connect(config.mongodb);
} catch (err) {
console.log(err);
console.log(colors.red("MongoDB: "), 'Error connecting to mongoDB');
process.exit(1);
}
// Create discord.js client
const { Client, GatewayIntentBits, EmbedBuilder } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMessageTyping,
GatewayIntentBits.DirectMessages
]
});
const bsl = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildPresences,
]
})
client.config = config;
bsl.config = config
// Set intents
client.on('ready', () => {
console.log(colors.green("Website: "), 'Website bot is ready!');
require('./website')
require('./website/bot')
require('./bsl')
});
// Login
client.login(client.config.bot.token);
bsl.login(bsl.config.bot.bsl.token);
bsl.on('rateLimit', (info) => {
console.log(`Rate limit hit ${info.timeDifference ? info.timeDifference : info.timeout ? info.timeout : 'Unknown timeout '}`)
})
// Node Error Handler
process.on('uncaughtException', function (err) {
console.log(err);
console.log('Uncaught Exception');
client.channels.cache.get(client.config.bot.channels.error).send(`Uncaught Exception: ${err}`);
});
// Node Exit Handler
process.on('exit', function (code) {
console.log('About to exit with code:', code);
client.channels.cache.get(client.config.bot.channels.error).send(`About to exit with code: ${code}`);
});
// Node Unhandled Rejection Handler
process.on('unhandledRejection', function (err) {
console.log(err);
console.log('Unhandled Rejection');
client.channels.cache.get(client.config.bot.channels.error).send(`Unhandled Rejection: ${err}`);
});
// Node Warning Handler
process.on('warning', function (warning) {
console.log(warning);
console.log('Warning');
client.channels.cache.get(client.config.bot.channels.error).send(`Warning: ${warning}`);
});
// Node Error Handler
process.on('error', function (err) {
console.log(err);
console.log('Error');
client.channels.cache.get(client.config.bot.channels.error).send(`Error: ${err}`);
});
// Node Disconnect Handler
process.on('disconnect', function (err) {
console.log(err);
console.log('Disconnect');
client.channels.cache.get(client.config.bot.channels.error).send(`Disconnect: ${err}`);
});
//export config
module.exports.config = config;
module.exports.mongoose = mongoose;
module.exports.client = client;
module.exports.bsl = bsl;
module.exports.embed = EmbedBuilder;
global.client = client;
global.bsl = bsl;
global.config = config;
global.discord = require('discord.js');