-
-
Notifications
You must be signed in to change notification settings - Fork 407
/
index.js
135 lines (107 loc) · 4.22 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
require('dotenv').config();
const fs = require('fs');
const Discord = require('discord.js');
const Client = require('./client/Client');
const config = require('./config.json');
const {Player} = require('discord-player');
const client = new Client();
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
console.log(client.commands);
const player = new Player(client);
player.extractors.loadDefault().then(r => console.log('Extractors loaded successfully'));
// Still needs to be refactored for 0.6
/*player.events.on('connection', (queue) => {
queue.connection.connec.voiceConnection.on('stateChange', (oldState, newState) => {
const oldNetworking = Reflect.get(oldState, 'networking');
const newNetworking = Reflect.get(newState, 'networking');
const networkStateChangeHandler = (oldNetworkState, newNetworkState) => {
const newUdp = Reflect.get(newNetworkState, 'udp');
clearInterval(newUdp?.keepAliveInterval);
}
oldNetworking?.off('stateChange', networkStateChangeHandler);
newNetworking?.on('stateChange', networkStateChangeHandler);
});
});*/
player.events.on('audioTrackAdd', (queue, song) => {
queue.metadata.channel.send(`🎶 | Song **${song.title}** added to the queue!`);
});
player.events.on('playerStart', (queue, track) => {
queue.metadata.channel.send(`▶ | Started playing: **${track.title}**!`);
});
player.events.on('audioTracksAdd', (queue, track) => {
queue.metadata.channel.send(`🎶 | Tracks have been queued!`);
});
player.events.on('disconnect', queue => {
queue.metadata.channel.send('❌ | I was manually disconnected from the voice channel, clearing queue!');
});
player.events.on('emptyChannel', queue => {
queue.metadata.channel.send('❌ | Nobody is in the voice channel, leaving...');
});
player.events.on('emptyQueue', queue => {
queue.metadata.channel.send('✅ | Queue finished!');
// Delete queue and disconnect from voice channel
queue.delete();
});
player.events.on('error', (queue, error) => {
console.log(`[${queue.guild.name}] Error emitted from the connection: ${error.message}`);
});
// For debugging
/*player.on('debug', async (message) => {
console.log(`General player debug event: ${message}`);
});
player.events.on('debug', async (queue, message) => {
console.log(`Player debug event: ${message}`);
});
player.events.on('playerError', (queue, error) => {
console.log(`Player error event: ${error.message}`);
console.log(error);
});*/
client.on('ready', function () {
console.log('Ready!');
client.user.presence.set({
activities: [{name: config.activity, type: Number(config.activityType)}],
status: Discord.Status.Ready,
});
});
client.once('reconnecting', () => {
console.log('Reconnecting!');
});
client.once('disconnect', () => {
console.log('Disconnect!');
});
client.on('messageCreate', async message => {
if (message.author.bot || !message.guild) return;
if (!client.application?.owner) await client.application?.fetch();
if (message.content === '!deploy' && message.author.id === client.application?.owner?.id) {
await message.guild.commands
.set(client.commands)
.then(() => {
message.reply('Deployed!');
})
.catch(err => {
message.reply('Could not deploy commands! Make sure the bot has the application.commands permission!');
console.error(err);
});
}
});
client.on('interactionCreate', async interaction => {
const command = client.commands.get(interaction.commandName.toLowerCase());
try {
if (interaction.commandName == 'ban' || interaction.commandName == 'userinfo') {
command.execute(interaction, client);
} else {
command.execute(interaction);
}
} catch (error) {
console.error(error);
await interaction.followUp({
content: 'There was an error trying to execute that command!',
});
}
});
client.login(process.env.DISCORD_TOKEN);