-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
99 lines (78 loc) · 2.82 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
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.on('error', (queue, error) => {
console.log(`[${queue.guild.name}] Error emitted from the queue: ${error.message}`);
});
player.on('connectionError', (queue, error) => {
console.log(`[${queue.guild.name}] Error emitted from the connection: ${error.message}`);
});
player.on('trackStart', (queue, track) => {
queue.metadata.send(`▶ | Started playing: **${track.title}** in **${queue.connection.channel.name}**!`);
});
player.on('trackAdd', (queue, track) => {
queue.metadata.send(`🎶 | Track **${track.title}** queued!`);
});
player.on('botDisconnect', queue => {
queue.metadata.send('❌ | I was manually disconnected from the voice channel, clearing queue!');
});
player.on('channelEmpty', queue => {
queue.metadata.send('❌ | Nobody is in the voice channel, leaving...Sigh');
});
player.on('queueEnd', queue => {
queue.metadata.send('✅ | Queue finished!');
});
client.once('ready', async () => {
console.log('Ready!');
});
client.on('ready', function() {
client.user.setActivity(config.activity, { type: config.activityType });
});
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, player);
}
} catch (error) {
console.error(error);
interaction.followUp({
content: 'Shit I fucked that up,There was an error trying to execute that command!',
});
}
});
client.login(config.token);