-
Notifications
You must be signed in to change notification settings - Fork 7
/
bot.js
56 lines (46 loc) · 1.58 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
require('dotenv').config();
const Client = require('./structures/Client');
const { Player } = require('discord-player');
const {
YouTubeExtractor,
SpotifyExtractor,
SoundCloudExtractor,
AppleMusicExtractor,
VimeoExtractor,
AttachmentExtractor,
ReverbnationExtractor } = require('@discord-player/extractor');
const fs = require('fs');
// Initialize client
const client = new Client();
// Initialize player
const player = new Player(client, {
autoRegisterExtractor: false,
ytdlOptions: { requestOptions: {
headers: { cookie: process.env.YOUTUBE_COOKIE ? process.env.YOUTUBE_COOKIE : null,
},
} },
});
// Register extractors to player
player.extractors.register(YouTubeExtractor);
player.extractors.register(SpotifyExtractor);
player.extractors.register(SoundCloudExtractor);
player.extractors.register(AppleMusicExtractor);
player.extractors.register(VimeoExtractor);
player.extractors.register(ReverbnationExtractor);
player.extractors.register(AttachmentExtractor);
// Load functions from ./functions
const functions = fs.readdirSync('./functions').filter((file) => file.endsWith('.js'));
for (const file of functions) {
require(`./functions/${file}`)(client);
}
// Initialize classes
client.events.player();
client.emoji();
client.login();
// Handle process events
process.on('uncaughtException', err => console.error(err.stack));
process.on('unhandledRejection', err => console.error(err.stack));
process.on('uncaughtExceptionMonitor', err => console.error(err.stack));
// Handle process exit
process.on('beforeExit', code => console.log(code));
process.on('exit', code => console.log(code));