-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
bot.js
117 lines (107 loc) · 3.47 KB
/
bot.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
const { Client, GatewayIntentBits, Partials } = require("discord.js");
const { DisTube } = require("distube");
const { SpotifyPlugin } = require("@distube/spotify");
const { SoundCloudPlugin } = require("@distube/soundcloud");
const { DeezerPlugin } = require("@distube/deezer");
const { YtDlpPlugin } = require("@distube/yt-dlp");
const config = require("./config.js");
const fs = require("fs");
const client = new Client({
partials: [
Partials.Channel, // for text channel
Partials.GuildMember, // for guild member
Partials.User, // for discord user
],
intents: [
GatewayIntentBits.Guilds, // for guild related things
GatewayIntentBits.GuildMembers, // for guild members related things
GatewayIntentBits.GuildIntegrations, // for discord Integrations
GatewayIntentBits.GuildVoiceStates, // for voice related things
],
});
client.config = config;
client.player = new DisTube(client, {
leaveOnStop: config.opt.voiceConfig.leaveOnStop,
leaveOnFinish: config.opt.voiceConfig.leaveOnFinish,
leaveOnEmpty: config.opt.voiceConfig.leaveOnEmpty.status,
emitNewSongOnly: true,
emitAddSongWhenCreatingQueue: false,
emitAddListWhenCreatingQueue: false,
plugins: [
new SpotifyPlugin(),
new SoundCloudPlugin(),
new YtDlpPlugin(),
new DeezerPlugin(),
],
});
const player = client.player;
client.language = config.language || "en";
let lang = require(`./languages/${config.language || "en"}.js`);
fs.readdir("./events", (_err, files) => {
files.forEach((file) => {
if (!file.endsWith(".js")) return;
const event = require(`./events/${file}`);
let eventName = file.split(".")[0];
console.log(`${lang.loadclientevent}: ${eventName}`);
client.on(eventName, event.bind(null, client));
delete require.cache[require.resolve(`./events/${file}`)];
});
});
fs.readdir("./events/player", (_err, files) => {
files.forEach((file) => {
if (!file.endsWith(".js")) return;
const player_events = require(`./events/player/${file}`);
let playerName = file.split(".")[0];
console.log(`${lang.loadevent}: ${playerName}`);
player.on(playerName, player_events.bind(null, client));
delete require.cache[require.resolve(`./events/player/${file}`)];
});
});
client.commands = [];
fs.readdir(config.commandsDir, (err, files) => {
if (err) throw err;
files.forEach(async (f) => {
try {
if (f.endsWith(".js")) {
let props = require(`${config.commandsDir}/${f}`);
client.commands.push({
name: props.name,
description: props.description,
options: props.options,
});
console.log(`${lang.loadcmd}: ${props.name}`);
}
} catch (err) {
console.log(err);
}
});
});
if (config.TOKEN || process.env.TOKEN) {
client.login(config.TOKEN || process.env.TOKEN).catch((e) => {
console.log(lang.error1);
});
} else {
setTimeout(() => {
console.log(lang.error2);
}, 2000);
}
if(config.mongodbURL || process.env.MONGO){
const mongoose = require("mongoose")
mongoose.connect(config.mongodbURL || process.env.MONGO, {
useNewUrlParser: true,
useUnifiedTopology: true,
}).then(async () => {
console.log(`Connected MongoDB`)
}).catch((err) => {
console.log("\nMongoDB Error: " + err + "\n\n" + lang.error4)
})
} else {
console.log(lang.error4)
}
const express = require("express");
const app = express();
const http = require("http");
app.get("/", (request, response) => {
response?.sendStatus(200);
});
app.listen(process?.env?.PORT);