forked from appujet/lavamusic
-
Notifications
You must be signed in to change notification settings - Fork 15
/
index.js
120 lines (111 loc) · 3.86 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
const { Client, Collection, Intents } = require("discord.js");
const array = [];
const { readdirSync } = require("fs");
const mongoose = require('mongoose');
const { Database } = require("quickmongo");
//const keepAlive = require('./keepAlive.js');
const { Manager } = require("erela.js");
const Spotify = require("erela.js-spotify");
const Deezer = require("erela.js-deezer");
const FaceBook = require("erela.js-facebook");
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_INVITES, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_VOICE_STATES],
allowedMentions: {
parse: ["everyone", "roles", "users"],
repliedUser: true
},
partials: ["CHANNEL", "GUILD_MEMBER", "MESSAGE", "REACTION", "USER"]
});
module.exports = client;
client.commands = new Collection();
client.slashCommands = new Collection();
client.config = require("./config.json");
client.db = new Database(client.config.mongourl);
client.owner = client.config.ownerID;
client.prefix = client.config.prefix;
client.embedColor = client.config.embedColor;
client.aliases = new Collection();
client.commands = new Collection();
client.categories = readdirSync("./commands/");
client.logger = require("./utils/logger.js");
client.emoji = require("./utils/emoji.json");
client.manager = new Manager({
nodes: client.config.nodes,
send: (id, payload) => {
const guild = client.guilds.cache.get(id);
if (guild) guild.shard.send(payload);
},
autoPlay: true,
plugins: [new Spotify({
clientID: client.config.SpotifyID,
clientSecret: client.config.SpotifySecret,
}),
new Deezer(),
new FaceBook()
],
});
client.on("raw", (d) => client.manager.updateVoiceState(d));
/**
* Mongodb connection
*/
const dbOptions = {
useNewUrlParser: true,
autoIndex: false,
poolSize: 5,
connectTimeoutMS: 10000,
family: 4,
useUnifiedTopology: true,
};
mongoose.connect(client.config.mongourl, dbOptions);
mongoose.set("useFindAndModify", false);
mongoose.Promise = global.Promise;
mongoose.connection.on('connected', () => {
client.logger.log('[DB] DATABASE CONNECTED', "ready");
});
mongoose.connection.on('err', (err) => {
console.log(`Mongoose connection error: \n ${err.stack}`, "error");
});
mongoose.connection.on('disconnected', () => {
console.log('Mongoose disconnected');
});
/**
* Error Handler
*/
client.on("disconnect", () => console.log("Bot is disconnecting..."))
client.on("reconnecting", () => console.log("Bot reconnecting..."))
client.on('warn', error => console.log(error));
client.on('error', error => console.log(error));
process.on('unhandledRejection', error => console.log(error));
process.on('uncaughtException', error => console.log(error));
/**
* Client Events
*/
readdirSync("./events/Client/").forEach(file => {
const event = require(`./events/Client/${file}`);
let eventName = file.split(".")[0];
client.logger.log(`Loading Events Client ${eventName}`, "event");
client.on(eventName, event.bind(null, client));
});
/**
* Erela Manager Events
*/
readdirSync("./events/Lavalink/").forEach(file => {
const event = require(`./events/Lavalink/${file}`);
let eventName = file.split(".")[0];
client.logger.log(`Loading Events Lavalink ${eventName}`, "event");
client.manager.on(eventName, event.bind(null, client));
});
/**
* Import all commands
*/
readdirSync("./commands/").forEach(dir => {
const commandFiles = readdirSync(`./commands/${dir}/`).filter(f => f.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${dir}/${file}`);
client.logger.log(`Loading ${command.category} commands ${command.name}`, "cmd");
client.commands.set(command.name, command);
}
});
///// Keep Alive Uptime Robot ///////
//keepAlive();
client.login(client.config.token);