forked from Koenie06/Discord.js-Music
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
81 lines (62 loc) · 3.09 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
/* Requiring all the needed stuff for the Command-Handler and client to work. */
const fs = require('fs');
const { Client, Collection, Intents } = require('discord.js');
const { token } = require('./config.json');
const music = require('@koenie06/discord.js-music');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_VOICE_STATES] });
module.exports.client = client;
/* This will run when a new song started to play */
music.event.on('playSong', (channel, songInfo, requester) => {
channel.send({ content: `Started playing the song [${songInfo.title}](${songInfo.url}) - ${songInfo.duration} | Requested by \`${requester.tag}\`` });
});
/* This will run when a new song has been added to the queue */
music.event.on('addSong', (channel, songInfo, requester) => {
channel.send({ content: `Added the song [${songInfo.title}](${songInfo.url}) - ${songInfo.duration} to the queue | Added by \`${requester.tag}\`` });
});
/* This will run when a song started playing from a playlist */
music.event.on('playList', async (channel, playlist, songInfo, requester) => {
channel.send({
content: `Started playing the song [${songInfo.title}](${songInfo.url}) by \`${songInfo.author}\` of the playlist ${playlist.title}.
This was requested by ${requester.tag} (${requester.id})`
});
});
/* This will run when a new playlist has been added to the queue */
music.event.on('addList', async (channel, playlist, requester) => {
channel.send({
content: `Added the playlist [${playlist.title}](${playlist.url}) with ${playlist.videos.length} amount of videos to the queue.
Added by ${requester.tag} (${requester.id})`
});
});
/* This will run when all the music has been played, and the bot disconnects. */
music.event.on('finish', (channel) => {
channel.send({ content: `All music has been played, disconnecting..` });
});
/* Setting every command in the 'commands' folder into the client.commands Collection. */
client.commands = new 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.data.name, command);
}
/* This code will run when the client has been logged in. */
client.on('ready', async() => {
console.log('I am online!');
});
/* This code will run when the client has received a Interaction. */
client.on('interactionCreate', async interaction => {
/* If it isn't a command, return. */
if (!interaction.isCommand()) return;
/* Getting all the setted client's commands that has been set in deploy-commands.js. */
const command = client.commands.get(interaction.commandName);
/* If there are no commands, return. */
if (!command) return;
/* Try executing the command. If this doesn't work, throw a error. */
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
};
});
/* Logging the client in */
client.login(token);