-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
85 lines (76 loc) · 3.26 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
import { Client, Collection } from "discord.js";
import config from './config.js';
import { readdirSync } from 'fs';
import mongoose from "mongoose";
import { Manager } from "erela.js";
import Spotify from "erela.js-spotify";
const client = new Client({ intents: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_MEMBERS', 'GUILD_VOICE_STATES'] });
client.commands = new Collection();
client.slashCommands = new Collection();
client.config = config;
client.color = config.color;
// Connect to mongoDB
mongoose.connect(config.db).then((connection) => {
console.log(`Connected to database : ${connection.connections[0].name}`);
}).catch((error) => {
console.log(`Unavle to connect to the database. Error : ${error}`);
});
// Lavalink client
client.manager = new Manager({
nodes: [config.lavalink],
send(id, payload) {
const guild = client.guilds.cache.get(id);
if (guild) guild.shard.send(payload);
},
plugins: [
new Spotify({
clientID: config.spotifyClientId,
clientSecret: config.spotifyClientSecret
})
]
});
// Load all client events
readdirSync('./events/client').filter((file) => file.endsWith('.js')).forEach((file) => {
import(`./events/client/${file}`).then((event) => {
event = event?.default;
if (!event?.run) return console.log(`Unable to load event : ${file}`);
event.name = event.name || file.replace('.js', '');
client.on(event.name, event.run.bind(null, client));
console.log(`Successfully loaded event : ${file}`);
});
});
// Load all commands
readdirSync('./commands').forEach((folder) => {
readdirSync(`./commands/${folder}`).filter((file) => file.endsWith('.js')).forEach((file) => {
import(`./commands/${folder}/${file}`).then((cmd) => {
cmd = cmd?.default;
if (!cmd?.run) return console.log(`Unable to load command : ${file}`);
cmd.name = cmd.name || file.replace('.js', '');
cmd.category = cmd.category || folder;
client.commands.set(cmd.name, cmd);
if (cmd.aliases && Array.isArray(cmd.aliases)) cmd.aliases.forEach((alias) => client.aliases.set(alias, cmd.name));
console.log(`Successfully loaded command : ${file}`);
});
});
});
// Load all slash commands
readdirSync('./slashCommands').forEach((folder) => {
readdirSync(`./slashCommands/${folder}`).filter((file) => file.endsWith('.js')).forEach((file) => {
let cmd = require(`./slashCommands/${folder}/${file}`);
if (!cmd?.run || !cmd?.data) return console.log(chalk.red(`Unable to load slash command : ${file}`));
let name = cmd.data.name;
client.slashCommands.set(name, cmd);
console.log(`Successfully loaded slash command : ${file}`);
});
});
// Load lavalink events
readdirSync('./events/lavalink').filter((file) => file.endsWith('.js')).forEach((file) => {
import(`./events/lavalink/${file}`).then((event) => {
event = event?.default;
if (!event?.run) return console.log(`Unable to load lavalink event : ${file}`);
event.name = event.name || file.replace('.js', '');
client.manager.on(event.name, event.run.bind(null, client));
console.log(`Successfully loaded lavalink event : ${file}`);
});
});
client.login(config.token);