-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
100 lines (92 loc) · 2.95 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
const { Client, GatewayIntentBits, Partials } = require("discord.js");
const { DisTube } = require("distube");
const { SpotifyPlugin } = require("@distube/spotify");
const { SoundCloudPlugin } = require("@distube/soundcloud");
const { YtDlpPlugin } = require("@distube/yt-dlp");
const config = require("./config");
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,
emitNewSongOnly: true,
emitAddSongWhenCreatingQueue: false,
emitAddListWhenCreatingQueue: false,
plugins: [
new SpotifyPlugin({
emitEventsAfterFetching: true,
}),
new SoundCloudPlugin(),
new YtDlpPlugin(),
],
});
const player = client.player;
client.language = config.language || "th";
let lang = require(`./languages/${config.language || "th"}.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);
}
const express = require("express");
const app = express();
app.get("/", (request, response) => {
response.sendStatus(200);
});
app.listen(process.env.PORT);