-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
75 lines (62 loc) · 2.64 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
const { Player } = require('discord-player');
const { Client, Intents, Collection } = require('discord.js');
const { readdirSync } = require('fs');
let client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_VOICE_STATES
],
disableMentions: 'everyone',
});
client.config = require('./config');
client.player = new Player(client, client.config.opt.discordPlayer);
client.commands = new Collection();
const player = client.player
const events = readdirSync('./events/').filter(file => file.endsWith('.js'));
for (const file of events) {
const event = require(`./events/${file}`);
console.log(`-> Loaded event ${file.split('.')[0]}`);
client.on(file.split('.')[0], event.bind(null, client));
delete require.cache[require.resolve(`./events/${file}`)];
};
console.log(`-> Loaded commands...`);
readdirSync('./commands/').forEach(dirs => {
const commands = readdirSync(`./commands/${dirs}`).filter(files => files.endsWith('.js'));
for (const file of commands) {
const command = require(`./commands/${dirs}/${file}`);
console.log(`${command.name.toLowerCase()} Load Command!`);
client.commands.set(command.name.toLowerCase(), command);
delete require.cache[require.resolve(`./commands/${dirs}/${file}`)];
};
});
player.on('error', (queue, error) => {
console.log(`There was a problem with the song queue => ${error.message}`);
});
player.on('connectionError', (queue, error) => {
console.log(`I'm having trouble connecting => ${error.message}`);
});
player.on('trackStart', (queue, track) => {
if (!client.config.opt.loopMessage && queue.repeatMode !== 0) return;
queue.metadata.send(`🎵 Music started playing: **${track.title}** -> Channel: **${queue.connection.channel.name}** 🎧`);
});
player.on('trackAdd', (queue, track) => {
queue.metadata.send(`**${track.title}** added to playlist. ✅`);
});
player.on('botDisconnect', (queue) => {
queue.metadata.send('Someone from the audio channel Im connected to kicked me out, the whole playlist has been cleared! ❌');
});
player.on('channelEmpty', (queue) => {
queue.metadata.send('I left the audio channel because there is no one on my audio channel. ❌');
});
player.on('queueEnd', (queue) => {
queue.metadata.send('All play queue finished, I think you can listen to some more music. ✅');
});
if(client.config.TOKEN){
client.login(client.config.TOKEN).catch(e => {
console.log("The bot token you entered was incorrect or intents are turned off.")
})
} else {
console.log("Please insert a bot token in the config.js file.")
}