diff --git a/LICENSE b/LICENSE index 528638d..d1f04e3 100644 --- a/LICENSE +++ b/LICENSE @@ -632,7 +632,7 @@ state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. A complete code to download for a Discord music bot. Using a module (discord-player). - Copyright (C) 2020 ZerioDev + Copyright (C) 2020-2021 ZerioDev This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: - Music-bot Copyright (C) 2020 ZerioDev + Music-bot Copyright (C) 2020-2021 ZerioDev This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. diff --git a/README.md b/README.md index 88a4ad8..b278432 100644 --- a/README.md +++ b/README.md @@ -1,91 +1,66 @@ # Music-bot -## Migrating to v5... - -Music-Bot has not been migrated to Discord Player v5 yet! It's on the way, feel free to add a star to this repository to show your support. In the meantime, you should use **[discord-music-bot](https://github.com/Androz2091/discord-music-bot)**. Please do not spam issues here as it should have probably been resolved in the new repo. Thanks. - -A complete code to download for a music bot. Using a module (discord-player) 🎧 +A complete code to download for a music bot 🎧 Looking for a code for a music bot ? This fully open source code is made for your project ! If you need help with this project, to get support faster you can join the help server by just clicking [here](https://discord.gg/5cGSYV8ZZj). -### ⚡ Installation +*If you don't have any development knowledge, it is recommended to join the Discord support server to get help.* -Well, let's start by downloading the code. -Go to the folder `config` then the file `bot.js`. -For the bot to be able to start, please complete the file with your credentials as follows : +### ⚡ Configuration -- For emojis +Open the configuration file located in the main folder `config.js`. ```js -emojis: { - off: ':x:', - error: ':warning:', - queue: ':bar_chart:', - music: ':musical_note:', - success: ':white_check_mark:', -} +module.exports = { + app: { + px: 'XXX', + token: 'XXX', + playing: 'by Zerio ❤️', + }, + + opt: { + DJ: { + enabled: false, + roleName: 'XXX', + commands: [] + }, + maxVol: 100, + discordPlayer: {} + } +}; ``` -- For configuration +Basic configuration -```js -discord: { - token: 'TOKEN', - prefix: 'PREFIX', - activity: 'ACTIVITY', -} -``` +- `app/px`, the prefix that will be set to use the bot +- `app/token`, the token of the bot available on the [Discord Developers](https://discordapp.com/developers/applications) section +- `app/playing`, the activity of the bot -- `token`, the token of the bot available on the [Discord Developers](https://discordapp.com/developers/applications) section. -- `prefix`, the prefix that will be set to use the bot. -- `activity`, the activity of the bot. +DJ mode configuration -In the console, type `npm install` to install all dependencies. +- `opt/DJ/enabled`, whether the DJ mode should be activated or not +- `opt/DJ/roleName`, the name of the DJ role to be used +- `opt/DJ/commands`, the list of commands limited to members with the DJ role -- To start the bot : +Advanced configuration -``` -#With Node -node index.js -npm start #Indicated in package.json +- `opt/maxVol`, the maximum volume that users can define +- `opt/discordPlayer`, options used by discord-player -#With pm2 -pm2 start index.js --name "MusicBot" -``` +### 📑 Installation -All you have to do is turn on your bot ! +To use the project correctly you will need some tools. -### 🎵 Music commands +[FFmpeg](https://www.ffmpeg.org) to process audio -``` -play , play music in a voice channel. -search , open a panel to choose a music and then play it. -pause, pause the current music. -resume, puts the current music back on. -queue, see the next songs. -clear-queue, remove music in the queue. -shuffle, to mix the queue. -nowplaying, see music in progress. -loop, to enable or disable the repeat function. -volume <1 - 100>, change the volume. -skip, skip to next music. -stop, stop all music. -filter , add / remove filter. -w-filters, see filters. -``` +[Node JS](https://nodejs.org/en/) (v16) for environment -### 💡 General commands +Without forgetting of course the code editor ^^ -``` -ping, see the bot latency. -help, see the list of available commands. -debug, see number of voice connections. -``` +Realized with ❤️ by [ZerioDev](https://github.com/ZerioDev). -### 🏓 Utilities (to change the code) +Please do not withdraw the license and keep the credits on this project. -Find all the functions available on the official code [right here](https://github.com/Androz2091/discord-player). - -This is used with [discord.js](https://www.npmjs.com/package/discord.js) and [discord-player](https://www.npmjs.com/package/discord-player). +To have full access to the project and to be able to withdraw the credits a small donation is accepted. \ No newline at end of file diff --git a/commands/core/help.js b/commands/core/help.js index 325dab4..2fa31d1 100644 --- a/commands/core/help.js +++ b/commands/core/help.js @@ -1,48 +1,25 @@ +const { MessageEmbed } = require('discord.js'); + module.exports = { name: 'help', aliases: ['h'], - category: 'Core', - utilisation: '{prefix}help ', + showHelp: false, + utilisation: '{prefix}help', execute(client, message, args) { - if (!args[0]) { - const infos = message.client.commands.filter(x => x.category == 'Infos').map((x) => '`' + x.name + '`').join(', '); - const music = message.client.commands.filter(x => x.category == 'Music').map((x) => '`' + x.name + '`').join(', '); + const embed = new MessageEmbed(); - message.channel.send({ - embed: { - color: 'ORANGE', - author: { name: 'Help pannel' }, - footer: { text: 'This bot uses a Github project made by Zerio (ZerioDev/Music-bot)' }, - fields: [ - { name: 'Bot', value: infos }, - { name: 'Music', value: music }, - { name: 'Filters', value: client.filters.map((x) => '`' + x + '`').join(', ') }, - ], - timestamp: new Date(), - description: `To use filters, ${client.config.discord.prefix}filter (the filter). Example : ${client.config.discord.prefix}filter 8D.`, - }, - }); - } else { - const command = message.client.commands.get(args.join(" ").toLowerCase()) || message.client.commands.find(x => x.aliases && x.aliases.includes(args.join(" ").toLowerCase())); + embed.setColor('RED'); + embed.setAuthor(client.user.username, client.user.displayAvatarURL({ size: 1024, dynamic: true })); - if (!command) return message.channel.send(`${client.emotes.error} - I did not find this command !`); + const commands = client.commands.filter(x => x.showHelp !== false); - message.channel.send({ - embed: { - color: 'ORANGE', - author: { name: 'Help pannel' }, - footer: { text: 'This bot uses a Github project made by Zerio (ZerioDev/Music-bot)' }, - fields: [ - { name: 'Name', value: command.name, inline: true }, - { name: 'Category', value: command.category, inline: true }, - { name: 'Aliase(s)', value: command.aliases.length < 1 ? 'None' : command.aliases.join(', '), inline: true }, - { name: 'Utilisation', value: command.utilisation.replace('{prefix}', client.config.discord.prefix), inline: true }, - ], - timestamp: new Date(), - description: 'Find information on the command provided.\nMandatory arguments `[]`, optional arguments `<>`.', - } - }); - }; + embed.setDescription('This code comes from a GitHub project (ZerioDev/Music-bot).\nThe use of this one is possible while keeping the credits for free.\nIf you want to remove the credits join the Discord support server.'); + embed.addField(`Enabled - ${commands.size}`, commands.map(x => `\`${x.name}${x.aliases[0] ? ` (${x.aliases.map(y => y).join(', ')})\`` : '\`'}`).join(' | ')); + + embed.setTimestamp(); + embed.setFooter('Music comes first - Made with heart by Zerio ❤️', message.author.avatarURL({ dynamic: true })); + + message.channel.send({ embeds: [embed] }); }, }; \ No newline at end of file diff --git a/commands/core/ping.js b/commands/core/ping.js new file mode 100644 index 0000000..6db100a --- /dev/null +++ b/commands/core/ping.js @@ -0,0 +1,11 @@ +const ms = require('ms'); + +module.exports = { + name: 'ping', + aliases: [], + utilisation: '{prefix}ping', + + execute(client, message) { + message.channel.send(`Last heartbeat calculated ${ms(Date.now() - client.ws.shards.first().lastPingTimestamp, { long: true })} ago **${client.ws.ping}ms** 🛰️`); + }, +}; \ No newline at end of file diff --git a/commands/infos/debug.js b/commands/infos/debug.js deleted file mode 100644 index fb0be53..0000000 --- a/commands/infos/debug.js +++ /dev/null @@ -1,10 +0,0 @@ -module.exports = { - name: 'debug', - aliases: [], - category: 'Infos', - utilisation: '{prefix}debug', - - execute(client, message) { - message.channel.send(`${client.emotes.success} - ${client.user.username} connected in **${client.voice.connections.size}** channels !`); - }, -}; \ No newline at end of file diff --git a/commands/infos/ping.js b/commands/infos/ping.js deleted file mode 100644 index 19cc447..0000000 --- a/commands/infos/ping.js +++ /dev/null @@ -1,10 +0,0 @@ -module.exports = { - name: 'ping', - aliases: [], - category: 'Infos', - utilisation: '{prefix}ping', - - execute(client, message) { - message.channel.send(`${client.emotes.success} - Ping : **${client.ws.ping}ms** !`); - }, -}; \ No newline at end of file diff --git a/commands/music/back.js b/commands/music/back.js new file mode 100644 index 0000000..7033dfb --- /dev/null +++ b/commands/music/back.js @@ -0,0 +1,18 @@ +module.exports = { + name: 'back', + aliases: ['previous'], + utilisation: '{prefix}back', + voiceChannel: true, + + async execute(client, message) { + const queue = player.getQueue(message.guild.id); + + if (!queue || !queue.playing) return message.channel.send(`No music currently playing ${message.author}... try again ? ❌`); + + if (!queue.previousTracks[1]) return message.channel.send(`There was no music played before ${message.author}... try again ? ❌`); + + await queue.back(); + + message.channel.send(`Playing the **previous** track ✅`); + }, +}; \ No newline at end of file diff --git a/commands/music/clear-queue.js b/commands/music/clear-queue.js deleted file mode 100644 index f1dc858..0000000 --- a/commands/music/clear-queue.js +++ /dev/null @@ -1,20 +0,0 @@ -module.exports = { - name: 'clear-queue', - aliases: ['cq'], - category: 'Music', - utilisation: '{prefix}clear-queue', - - execute(client, message) { - if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); - - if (message.guild.me.voice.channel && message.member.voice.channel.id !== message.guild.me.voice.channel.id) return message.channel.send(`${client.emotes.error} - You are not in the same voice channel !`); - - if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); - - if (client.player.getQueue(message).tracks.length <= 1) return message.channel.send(`${client.emotes.error} - There is only one song in the queue.`); - - client.player.clearQueue(message); - - message.channel.send(`${client.emotes.success} - The queue has just been **removed** !`); - }, -}; \ No newline at end of file diff --git a/commands/music/clear.js b/commands/music/clear.js new file mode 100644 index 0000000..1f05f56 --- /dev/null +++ b/commands/music/clear.js @@ -0,0 +1,18 @@ +module.exports = { + name: 'clear', + aliases: ['cq'], + utilisation: '{prefix}clear', + voiceChannel: true, + + async execute(client, message) { + const queue = player.getQueue(message.guild.id); + + if (!queue || !queue.playing) return message.channel.send(`No music currently playing ${message.author}... try again ? ❌`); + + if (!queue.tracks[0]) return message.channel.send(`No music in the queue after the current one ${message.author}... try again ? ❌`); + + await queue.clear(); + + message.channel.send(`The queue has just been cleared 🗑️`); + }, +}; \ No newline at end of file diff --git a/commands/music/filter.js b/commands/music/filter.js index b82a692..9f7d1dd 100644 --- a/commands/music/filter.js +++ b/commands/music/filter.js @@ -1,29 +1,33 @@ module.exports = { name: 'filter', aliases: [], - category: 'Music', utilisation: '{prefix}filter [filter name]', + voiceChannel: true, - execute(client, message, args) { - if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); + async execute(client, message, args) { + const queue = player.getQueue(message.guild.id); - if (message.guild.me.voice.channel && message.member.voice.channel.id !== message.guild.me.voice.channel.id) return message.channel.send(`${client.emotes.error} - You are not in the same voice channel !`); + if (!queue || !queue.playing) return message.channel.send(`No music currently playing ${message.author}... try again ? ❌`); - if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); + const actualFilter = queue.getFiltersEnabled()[0]; - if (!args[0]) return message.channel.send(`${client.emotes.error} - Please specify a valid filter to enable or disable !`); + if (!args[0]) return message.channel.send(`Please specify a valid filter to enable or disable ${message.author}... try again ? ❌\n${actualFilter ? `Filter currently active ${actualFilter} (${client.config.app.px}filter ${actualFilter} to disable it).\n` : ''}`); - const filterToUpdate = client.filters.find((x) => x.toLowerCase() === args[0].toLowerCase()); + const filters = []; - if (!filterToUpdate) return message.channel.send(`${client.emotes.error} - This filter doesn't exist, try for example (8D, vibrato, pulsator...) !`); + queue.getFiltersEnabled().map(x => filters.push(x)); + queue.getFiltersDisabled().map(x => filters.push(x)); + + const filter = filters.find((x) => x.toLowerCase() === args[0].toLowerCase()); + + if (!filter) return message.channel.send(`This filter doesn't exist ${message.author}... try again ? ❌\n${actualFilter ? `Filter currently active ${actualFilter}.\n` : ''}List of available filters ${filters.map(x => `**${x}**`).join(', ')}.`); const filtersUpdated = {}; - filtersUpdated[filterToUpdate] = client.player.getQueue(message).filters[filterToUpdate] ? false : true; + filtersUpdated[filter] = queue.getFiltersEnabled().includes(filter) ? false : true; - client.player.setFilters(message, filtersUpdated); + await queue.setFilters(filtersUpdated); - if (filtersUpdated[filterToUpdate]) message.channel.send(`${client.emotes.music} - I'm **adding** the filter to the music, please wait... Note : the longer the music is, the longer this will take.`); - else message.channel.send(`${client.emotes.music} - I'm **disabling** the filter on the music, please wait... Note : the longer the music is playing, the longer this will take.`); + message.channel.send(`The filter ${filter} is now **${queue.getFiltersEnabled().includes(filter) ? 'enabled' : 'disabled'}** ✅\n*Reminder the longer the music is, the longer this will take.*`); }, }; \ No newline at end of file diff --git a/commands/music/loop.js b/commands/music/loop.js index 4e39052..0485531 100644 --- a/commands/music/loop.js +++ b/commands/music/loop.js @@ -1,32 +1,28 @@ +const { QueueRepeatMode } = require('discord-player'); + module.exports = { name: 'loop', aliases: ['lp', 'repeat'], - category: 'Music', - utilisation: '{prefix}loop', + utilisation: '{prefix}loop ', + voiceChannel: true, execute(client, message, args) { - if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); + const queue = player.getQueue(message.guild.id); - if (message.guild.me.voice.channel && message.member.voice.channel.id !== message.guild.me.voice.channel.id) return message.channel.send(`${client.emotes.error} - You are not in the same voice channel !`); + if (!queue || !queue.playing) return message.channel.send(`No music currently playing ${message.author}... try again ? ❌`); - if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); + if (args.join('').toLowerCase() === 'queue') { + if (queue.repeatMode === 1) return message.channel.send(`You must first disable the current music in the loop mode (${client.config.app.px}loop) ${message.author}... try again ? ❌`); - if (args.join(" ").toLowerCase() === 'queue') { - if (client.player.getQueue(message).loopMode) { - client.player.setLoopMode(message, false); - return message.channel.send(`${client.emotes.success} - Repeat mode **disabled** !`); - } else { - client.player.setLoopMode(message, true); - return message.channel.send(`${client.emotes.success} - Repeat mode **enabled** the whole queue will be repeated endlessly !`); - }; + const success = queue.setRepeatMode(queue.repeatMode === 0 ? QueueRepeatMode.QUEUE : QueueRepeatMode.OFF); + + return message.channel.send(success ? `Repeat mode **${queue.repeatMode === 0 ? 'disabled' : 'enabled'}** the whole queue will be repeated endlessly 🔁` : `Something went wrong ${message.author}... try again ? ❌`); } else { - if (client.player.getQueue(message).repeatMode) { - client.player.setRepeatMode(message, false); - return message.channel.send(`${client.emotes.success} - Repeat mode **disabled** !`); - } else { - client.player.setRepeatMode(message, true); - return message.channel.send(`${client.emotes.success} - Repeat mode **enabled** the current music will be repeated endlessly !`); - }; + if (queue.repeatMode === 2) return message.channel.send(`You must first disable the current queue in the loop mode (${client.config.app.px}loop queue) ${message.author}... try again ? ❌`); + + const success = queue.setRepeatMode(queue.repeatMode === 0 ? QueueRepeatMode.TRACK : QueueRepeatMode.OFF); + + return message.channel.send(success ? `Repeat mode **${queue.repeatMode === 0 ? 'disabled' : 'enabled'}** the current music will be repeated endlessly (you can loop the queue with the option) 🔂` : `Something went wrong ${message.author}... try again ? ❌`); }; }, }; \ No newline at end of file diff --git a/commands/music/nowplaying.js b/commands/music/nowplaying.js index 4acac1c..3bae84c 100644 --- a/commands/music/nowplaying.js +++ b/commands/music/nowplaying.js @@ -1,44 +1,31 @@ +const { MessageEmbed } = require('discord.js'); + module.exports = { name: 'nowplaying', aliases: ['np'], - category: 'Music', utilisation: '{prefix}nowplaying', + voiceChannel: true, execute(client, message) { - if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); + const queue = player.getQueue(message.guild.id); - if (message.guild.me.voice.channel && message.member.voice.channel.id !== message.guild.me.voice.channel.id) return message.channel.send(`${client.emotes.error} - You are not in the same voice channel !`); + if (!queue || !queue.playing) return message.channel.send(`No music currently playing ${message.author}... try again ? ❌`); - if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); + const track = queue.current; - const track = client.player.nowPlaying(message); - const filters = []; + const embed = new MessageEmbed(); - Object.keys(client.player.getQueue(message).filters).forEach((filterName) => client.player.getQueue(message).filters[filterName]) ? filters.push(filterName) : false; + embed.setColor('RED'); + embed.setThumbnail(track.thumbnail); + embed.setAuthor(track.title, client.user.displayAvatarURL({ size: 1024, dynamic: true })); - message.channel.send({ - embed: { - color: 'RED', - author: { name: track.title }, - footer: { text: 'This bot uses a Github project made by Zerio (ZerioDev/Music-bot)' }, - fields: [ - { name: 'Channel', value: track.author, inline: true }, - { name: 'Requested by', value: track.requestedBy.username, inline: true }, - { name: 'From playlist', value: track.fromPlaylist ? 'Yes' : 'No', inline: true }, + const methods = ['disabled', 'track', 'queue']; - { name: 'Views', value: track.views, inline: true }, - { name: 'Duration', value: track.duration, inline: true }, - { name: 'Filters activated', value: filters.length + '/' + client.filters.length, inline: true }, + embed.setDescription(`Volume **${queue.volume}**%\nDuration **${track.duration}**\nLoop mode **${methods[queue.repeatMode]}**\nRequested by ${track.requestedBy}`); - { name: 'Volume', value: client.player.getQueue(message).volume, inline: true }, - { name: 'Repeat mode', value: client.player.getQueue(message).repeatMode ? 'Yes' : 'No', inline: true }, - { name: 'Currently paused', value: client.player.getQueue(message).paused ? 'Yes' : 'No', inline: true }, + embed.setTimestamp(); + embed.setFooter('Music comes first - Made with heart by Zerio ❤️', message.author.avatarURL({ dynamic: true })); - { name: 'Progress bar', value: client.player.createProgressBar(message, { timecodes: true }), inline: true } - ], - thumbnail: { url: track.thumbnail }, - timestamp: new Date(), - }, - }); + message.channel.send({ embeds: [embed] }); }, }; \ No newline at end of file diff --git a/commands/music/pause.js b/commands/music/pause.js index 0e9e7b2..27d6b2f 100644 --- a/commands/music/pause.js +++ b/commands/music/pause.js @@ -1,20 +1,16 @@ module.exports = { name: 'pause', aliases: [], - category: 'Music', utilisation: '{prefix}pause', + voiceChannel: true, execute(client, message) { - if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); + const queue = player.getQueue(message.guild.id); - if (message.guild.me.voice.channel && message.member.voice.channel.id !== message.guild.me.voice.channel.id) return message.channel.send(`${client.emotes.error} - You are not in the same voice channel !`); + if (!queue) return message.channel.send(`No music currently playing ${message.author}... try again ? ❌`); - if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); + const success = queue.setPaused(true); - if (client.player.getQueue(message).paused) return message.channel.send(`${client.emotes.error} - The music is already paused !`); - - const success = client.player.pause(message); - - if (success) message.channel.send(`${client.emotes.success} - Song ${client.player.getQueue(message).playing.title} paused !`); + return message.channel.send(success ? `Current music ${queue.current.title} paused ✅` : `Something went wrong ${message.author}... try again ? ❌`); }, }; \ No newline at end of file diff --git a/commands/music/play.js b/commands/music/play.js index 0623a1e..fd964ba 100644 --- a/commands/music/play.js +++ b/commands/music/play.js @@ -1,16 +1,36 @@ +const { QueryType } = require('discord-player'); + module.exports = { name: 'play', aliases: ['p'], - category: 'Music', - utilisation: '{prefix}play [name/URL]', + utilisation: '{prefix}play [song name/URL]', + voiceChannel: true, - execute(client, message, args) { - if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); + async execute(client, message, args) { + if (!args[0]) return message.channel.send(`Please enter a valid search ${message.author}... try again ? ❌`); - if (message.guild.me.voice.channel && message.member.voice.channel.id !== message.guild.me.voice.channel.id) return message.channel.send(`${client.emotes.error} - You are not in the same voice channel !`); + const res = await player.search(args.join(' '), { + requestedBy: message.member, + searchEngine: QueryType.AUTO + }); - if (!args[0]) return message.channel.send(`${client.emotes.error} - Please indicate the title of a song !`); + if (!res || !res.tracks.length) return message.channel.send(`No results found ${message.author}... try again ? ❌`); - client.player.play(message, args.join(" "), { firstResult: true }); + const queue = await player.createQueue(message.guild, { + metadata: message.channel + }); + + try { + if (!queue.connection) await queue.connect(message.member.voice.channel); + } catch { + await player.deleteQueue(message.guild.id); + return message.channel.send(`I can't join the voice channel ${message.author}... try again ? ❌`); + } + + await message.channel.send(`Loading your ${res.playlist ? 'playlist' : 'track'}... 🎧`); + + res.playlist ? queue.addTracks(res.tracks) : queue.addTrack(res.tracks[0]); + + if (!queue.playing) await queue.play(); }, }; \ No newline at end of file diff --git a/commands/music/queue.js b/commands/music/queue.js index de5af8c..2db79a8 100644 --- a/commands/music/queue.js +++ b/commands/music/queue.js @@ -1,20 +1,35 @@ +const { MessageEmbed } = require('discord.js'); + module.exports = { name: 'queue', - aliases: [], - category: 'Music', + aliases: ['q'], utilisation: '{prefix}queue', + voiceChannel: true, execute(client, message) { - if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); + const queue = player.getQueue(message.guild.id); - if (message.guild.me.voice.channel && message.member.voice.channel.id !== message.guild.me.voice.channel.id) return message.channel.send(`${client.emotes.error} - You are not in the same voice channel !`); + if (!queue) return message.channel.send(`No music currently playing ${message.author}... try again ? ❌`); - const queue = client.player.getQueue(message); + if (!queue.tracks[0]) return message.channel.send(`No music in the queue after the current one ${message.author}... try again ? ❌`); - if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No songs currently playing !`); + const embed = new MessageEmbed(); + const methods = ['', '🔁', '🔂']; - message.channel.send(`**Server queue - ${message.guild.name} ${client.emotes.queue} ${client.player.getQueue(message).loopMode ? '(looped)' : ''}**\nCurrent : ${queue.playing.title} | ${queue.playing.author}\n\n` + (queue.tracks.map((track, i) => { - return `**#${i + 1}** - ${track.title} | ${track.author} (requested by : ${track.requestedBy.username})` - }).slice(0, 5).join('\n') + `\n\n${queue.tracks.length > 5 ? `And **${queue.tracks.length - 5}** other songs...` : `In the playlist **${queue.tracks.length}** song(s)...`}`)); + embed.setColor('RED'); + embed.setThumbnail(message.guild.iconURL({ size: 2048, dynamic: true })); + embed.setAuthor(`Server queue - ${message.guild.name} ${methods[queue.repeatMode]}`, client.user.displayAvatarURL({ size: 1024, dynamic: true })); + + const tracks = queue.tracks.map((track, i) => `**${i + 1}** - ${track.title} | ${track.author} (requested by : ${track.requestedBy.username})`); + + const songs = queue.tracks.length; + const nextSongs = songs > 5 ? `And **${songs - 5}** other song(s)...` : `In the playlist **${songs}** song(s)...`; + + embed.setDescription(`Current ${queue.current.title}\n\n${tracks.slice(0, 5).join('\n')}\n\n${nextSongs}`); + + embed.setTimestamp(); + embed.setFooter('Music comes first - Made with heart by Zerio ❤️', message.author.avatarURL({ dynamic: true })); + + message.channel.send({ embeds: [embed] }); }, }; \ No newline at end of file diff --git a/commands/music/resume.js b/commands/music/resume.js index f3821c4..36683a9 100644 --- a/commands/music/resume.js +++ b/commands/music/resume.js @@ -1,20 +1,16 @@ module.exports = { name: 'resume', - aliases: [], - category: 'Music', + aliases: ['rs'], utilisation: '{prefix}resume', + voiceChannel: true, execute(client, message) { - if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); + const queue = player.getQueue(message.guild.id); - if (message.guild.me.voice.channel && message.member.voice.channel.id !== message.guild.me.voice.channel.id) return message.channel.send(`${client.emotes.error} - You are not in the same voice channel !`); + if (!queue) return message.channel.send(`No music currently playing ${message.author}... try again ? ❌`); - if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); + const success = queue.setPaused(false); - if (!client.player.getQueue(message).paused) return message.channel.send(`${client.emotes.error} - The music is already playing !`); - - const success = client.player.resume(message); - - if (success) message.channel.send(`${client.emotes.success} - Song ${client.player.getQueue(message).playing.title} resumed !`); + return message.channel.send(success ? `Current music ${queue.current.title} resumed ✅` : `Something went wrong ${message.author}... try again ? ❌`); }, }; \ No newline at end of file diff --git a/commands/music/save.js b/commands/music/save.js new file mode 100644 index 0000000..1129443 --- /dev/null +++ b/commands/music/save.js @@ -0,0 +1,18 @@ +module.exports = { + name: 'save', + aliases: ['sv'], + utilisation: '{prefix}save', + voiceChannel: true, + + async execute(client, message) { + const queue = player.getQueue(message.guild.id); + + if (!queue || !queue.playing) return message.channel.send(`No music currently playing ${message.author}... try again ? ❌`); + + message.author.send(`You saved the track ${queue.current.title} | ${queue.current.author} from the server ${message.guild.name} ✅`).then(() => { + message.channel.send(`I have sent you the title of the music by private messages ✅`); + }).catch(error => { + message.channel.send(`Unable to send you a private message ${message.author}... try again ? ❌`); + }); + }, +}; \ No newline at end of file diff --git a/commands/music/search.js b/commands/music/search.js deleted file mode 100644 index bbd501a..0000000 --- a/commands/music/search.js +++ /dev/null @@ -1,16 +0,0 @@ -module.exports = { - name: 'search', - aliases: ['sr'], - category: 'Music', - utilisation: '{prefix}search [name/URL]', - - execute(client, message, args) { - if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); - - if (message.guild.me.voice.channel && message.member.voice.channel.id !== message.guild.me.voice.channel.id) return message.channel.send(`${client.emotes.error} - You are not in the same voice channel !`); - - if (!args[0]) return message.channel.send(`${client.emotes.error} - Please indicate the title of a song !`); - - client.player.play(message, args.join(" ")); - }, -}; \ No newline at end of file diff --git a/commands/music/seek.js b/commands/music/seek.js new file mode 100644 index 0000000..2f4cfd2 --- /dev/null +++ b/commands/music/seek.js @@ -0,0 +1,22 @@ +const ms = require('ms'); + +module.exports = { + name: 'seek', + aliases: [], + utilisation: '{prefix}seek [time]', + voiceChannel: true, + + async execute(client, message, args) { + const queue = player.getQueue(message.guild.id); + + if (!queue || !queue.playing) return message.channel.send(`No music currently playing ${message.author}... try again ? ❌`); + + const timeToMS = ms(args.join(' ')); + + if (timeToMS >= queue.current.durationMS) return message.channel.send(`The indicated time is higher than the total time of the current song ${message.author}... try again ? ❌\n*Try for example a valid time like **5s, 10s, 20 seconds, 1m**...*`); + + await queue.seek(timeToMS); + + message.channel.send(`Time set on the current song **${ms(timeToMS, { long: true })}** ✅`); + }, +}; \ No newline at end of file diff --git a/commands/music/shuffle.js b/commands/music/shuffle.js index efedfd2..8d2f440 100644 --- a/commands/music/shuffle.js +++ b/commands/music/shuffle.js @@ -1,18 +1,18 @@ module.exports = { name: 'shuffle', aliases: ['sh'], - category: 'Music', utilisation: '{prefix}shuffle', + voiceChannel: true, - execute(client, message) { - if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); + async execute(client, message) { + const queue = player.getQueue(message.guild.id); - if (message.guild.me.voice.channel && message.member.voice.channel.id !== message.guild.me.voice.channel.id) return message.channel.send(`${client.emotes.error} - You are not in the same voice channel !`); + if (!queue || !queue.playing) return message.channel.send(`No music currently playing ${message.author}... try again ? ❌`); - if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); + if (!queue.tracks[0]) return message.channel.send(`No music in the queue after the current one ${message.author}... try again ? ❌`); - const success = client.player.shuffle(message); + await queue.shuffle(); - if (success) message.channel.send(`${client.emotes.success} - Queue shuffled **${client.player.getQueue(message).tracks.length}** song(s) !`); + return message.channel.send(`Queue shuffled **${queue.tracks.length}** song(s) ! ✅`); }, }; \ No newline at end of file diff --git a/commands/music/skip.js b/commands/music/skip.js index 6ac02b5..1c99095 100644 --- a/commands/music/skip.js +++ b/commands/music/skip.js @@ -1,18 +1,16 @@ module.exports = { name: 'skip', aliases: ['sk'], - category: 'Music', utilisation: '{prefix}skip', + voiceChannel: true, execute(client, message) { - if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); + const queue = player.getQueue(message.guild.id); - if (message.guild.me.voice.channel && message.member.voice.channel.id !== message.guild.me.voice.channel.id) return message.channel.send(`${client.emotes.error} - You are not in the same voice channel !`); + if (!queue || !queue.playing) return message.channel.send(`No music currently playing ${message.author}... try again ? ❌`); - if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); + const success = queue.skip(); - const success = client.player.skip(message); - - if (success) message.channel.send(`${client.emotes.success} - The current music has just been **skipped** !`); + return message.channel.send(success ? `Current music ${queue.current.title} skipped ✅` : `Something went wrong ${message.author}... try again ? ❌`); }, }; \ No newline at end of file diff --git a/commands/music/stop.js b/commands/music/stop.js index 1dcbde4..7999a1a 100644 --- a/commands/music/stop.js +++ b/commands/music/stop.js @@ -1,19 +1,16 @@ module.exports = { name: 'stop', aliases: ['dc'], - category: 'Music', utilisation: '{prefix}stop', + voiceChannel: true, execute(client, message) { - if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); + const queue = player.getQueue(message.guild.id); - if (message.guild.me.voice.channel && message.member.voice.channel.id !== message.guild.me.voice.channel.id) return message.channel.send(`${client.emotes.error} - You are not in the same voice channel !`); + if (!queue || !queue.playing) return message.channel.send(`No music currently playing ${message.author}... try again ? ❌`); - if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); + queue.destroy(); - client.player.setRepeatMode(message, false); - const success = client.player.stop(message); - - if (success) message.channel.send(`${client.emotes.success} - Music **stopped** into this server !`); + message.channel.send(`Music stopped into this server, see you next time ✅`); }, }; \ No newline at end of file diff --git a/commands/music/volume.js b/commands/music/volume.js index 4f36f89..928c6f8 100644 --- a/commands/music/volume.js +++ b/commands/music/volume.js @@ -1,22 +1,26 @@ +const maxVol = client.config.opt.maxVol; + module.exports = { name: 'volume', - aliases: [], - category: 'Music', - utilisation: '{prefix}volume [1-100]', + aliases: ['vol'], + utilisation: `{prefix}volume [1-${maxVol}]`, + voiceChannel: true, execute(client, message, args) { - if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); + const queue = player.getQueue(message.guild.id); - if (message.guild.me.voice.channel && message.member.voice.channel.id !== message.guild.me.voice.channel.id) return message.channel.send(`${client.emotes.error} - You are not in the same voice channel !`); + if (!queue || !queue.playing) return message.channel.send(`No music currently playing ${message.author}... try again ? ❌`); - if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); + const vol = parseInt(args[0]); - if (!args[0] || isNaN(args[0]) || args[0] === 'Infinity') return message.channel.send(`${client.emotes.error} - Please enter a valid number !`); + if (!vol) return message.channel.send(`The current volume is ${queue.volume} 🔊\n*To change the volume enter a valid number between **1** and **${maxVol}**.*`); - if (Math.round(parseInt(args[0])) < 1 || Math.round(parseInt(args[0])) > 100) return message.channel.send(`${client.emotes.error} - Please enter a valid number (between 1 and 100) !`); + if (queue.volume === vol) return message.channel.send(`The volume you want to change is already the current one ${message.author}... try again ? ❌`); - const success = client.player.setVolume(message, parseInt(args[0])); + if (vol < 0 || vol > maxVol) return message.channel.send(`The specified number is not valid. Enter a number between **1** and **${maxVol}** ${message.author}... try again ? ❌`); - if (success) message.channel.send(`${client.emotes.success} - Volume set to **${parseInt(args[0])}%** !`); + const success = queue.setVolume(vol); + + return message.channel.send(success ? `The volume has been modified to **${vol}**/**${maxVol}**% 🔊` : `Something went wrong ${message.author}... try again ? ❌`); }, }; \ No newline at end of file diff --git a/commands/music/w-filters.js b/commands/music/w-filters.js deleted file mode 100644 index 4771846..0000000 --- a/commands/music/w-filters.js +++ /dev/null @@ -1,34 +0,0 @@ -module.exports = { - name: 'w-filters', - aliases: ['filters'], - category: 'Music', - utilisation: '{prefix}w-filters', - - execute(client, message) { - if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); - - if (message.guild.me.voice.channel && message.member.voice.channel.id !== message.guild.me.voice.channel.id) return message.channel.send(`${client.emotes.error} - You are not in the same voice channel !`); - - if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); - - const filtersStatuses = [[], []]; - - client.filters.forEach((filterName) => { - const array = filtersStatuses[0].length > filtersStatuses[1].length ? filtersStatuses[1] : filtersStatuses[0]; - array.push(filterName.charAt(0).toUpperCase() + filterName.slice(1) + " : " + (client.player.getQueue(message).filters[filterName] ? client.emotes.success : client.emotes.off)); - }); - - message.channel.send({ - embed: { - color: 'ORANGE', - footer: { text: 'This bot uses a Github project made by Zerio (ZerioDev/Music-bot)' }, - fields: [ - { name: 'Filters', value: filtersStatuses[0].join('\n'), inline: true }, - { name: '** **', value: filtersStatuses[1].join('\n'), inline: true }, - ], - timestamp: new Date(), - description: `List of all filters enabled or disabled.\nUse \`${client.config.discord.prefix}filter\` to add a filter to a song.`, - }, - }); - }, -}; \ No newline at end of file diff --git a/config.js b/config.js new file mode 100644 index 0000000..59ac022 --- /dev/null +++ b/config.js @@ -0,0 +1,17 @@ +module.exports = { + app: { + px: 'XXX', + token: 'XXX', + playing: 'by Zerio ❤️', + }, + + opt: { + DJ: { + enabled: false, + roleName: 'DJ', + commands: ['back', 'clear', 'filter', 'loop', 'pause', 'resume', 'seek', 'shuffle', 'skip', 'stop', 'volume'] + }, + maxVol: 100, + discordPlayer: {} + } +}; \ No newline at end of file diff --git a/config/bot.js b/config/bot.js deleted file mode 100644 index f504a11..0000000 --- a/config/bot.js +++ /dev/null @@ -1,17 +0,0 @@ -module.exports = { - emojis: { - off: ':x:', - error: ':warning:', - queue: ':bar_chart:', - music: ':musical_note:', - success: ':white_check_mark:', - }, - - discord: { - token: 'TOKEN', - prefix: 'PREFIX', - activity: 'ACTIVITY', - }, - - filters: ['8D', 'gate', 'haas', 'phaser', 'treble', 'tremolo', 'vibrato', 'reverse', 'karaoke', 'flanger', 'mcompand', 'pulsator', 'subboost', 'bassboost', 'vaporwave', 'nightcore', 'normalizer', 'surrounding'], -}; \ No newline at end of file diff --git a/events/message.js b/events/message.js deleted file mode 100644 index 5c685af..0000000 --- a/events/message.js +++ /dev/null @@ -1,14 +0,0 @@ -module.exports = (client, message) => { - if (message.author.bot || message.channel.type === 'dm') return; - - const prefix = client.config.discord.prefix; - - if (message.content.indexOf(prefix) !== 0) return; - - const args = message.content.slice(prefix.length).trim().split(/ +/g); - const command = args.shift().toLowerCase(); - - const cmd = client.commands.get(command) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(command)); - - if (cmd) cmd.execute(client, message, args); -}; \ No newline at end of file diff --git a/events/messageCreate.js b/events/messageCreate.js new file mode 100644 index 0000000..7cb9502 --- /dev/null +++ b/events/messageCreate.js @@ -0,0 +1,30 @@ +module.exports = (client, message) => { + if (message.author.bot || message.channel.type === 'dm') return; + + const prefix = client.config.app.px; + + if (message.content.indexOf(prefix) !== 0) return; + + const args = message.content.slice(prefix.length).trim().split(/ +/g); + const command = args.shift().toLowerCase(); + + const cmd = client.commands.get(command) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(command)); + + const DJ = client.config.opt.DJ; + + if (cmd && DJ.enabled && DJ.commands.includes(cmd.name)) { + const roleDJ = message.guild.roles.cache.find(x => x.name === DJ.roleName); + + if (!message.member._roles.includes(roleDJ.id)) { + return message.channel.send(`This command is reserved for members with the ${DJ.roleName} role on the server ${message.author}... try again ? ❌`); + } + } + + if (cmd && cmd.voiceChannel) { + if (!message.member.voice.channel) return message.channel.send(`You're not in a voice channel ${message.author}... try again ? ❌`); + + if (message.guild.me.voice.channel && message.member.voice.channel.id !== message.guild.me.voice.channel.id) return message.channel.send(`You are not in the same voice channel ${message.author}... try again ? ❌`); + } + + if (cmd) cmd.execute(client, message, args); +}; \ No newline at end of file diff --git a/events/ready.js b/events/ready.js index d8ca2f7..b38fd0f 100644 --- a/events/ready.js +++ b/events/ready.js @@ -1,5 +1,5 @@ module.exports = async (client) => { - console.log(`Logged in as ${client.user.username}. Ready on ${client.guilds.cache.size} servers, for a total of ${client.users.cache.size} users`); + console.log(`Logged to the client ${client.user.username}\n-> Ready on ${client.guilds.cache.size} servers for a total of ${client.users.cache.size} users`); - client.user.setActivity(client.config.discord.activity); + client.user.setActivity(client.config.app.playing); }; \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index f5c3c9c..0000000 --- a/index.js +++ /dev/null @@ -1,39 +0,0 @@ -const fs = require('fs'); -const discord = require('discord.js'); - -const client = new discord.Client({ disableMentions: 'everyone' }); - -const { Player } = require('discord-player'); - -client.player = new Player(client); -client.config = require('./config/bot'); -client.emotes = client.config.emojis; -client.filters = client.config.filters; -client.commands = new discord.Collection(); - -fs.readdirSync('./commands').forEach(dirs => { - const commands = fs.readdirSync(`./commands/${dirs}`).filter(files => files.endsWith('.js')); - - for (const file of commands) { - const command = require(`./commands/${dirs}/${file}`); - console.log(`Loading command ${file}`); - client.commands.set(command.name.toLowerCase(), command); - }; -}); - -const events = fs.readdirSync('./events').filter(file => file.endsWith('.js')); -const player = fs.readdirSync('./player').filter(file => file.endsWith('.js')); - -for (const file of events) { - console.log(`Loading discord.js event ${file}`); - const event = require(`./events/${file}`); - client.on(file.split(".")[0], event.bind(null, client)); -}; - -for (const file of player) { - console.log(`Loading discord-player event ${file}`); - const event = require(`./player/${file}`); - client.player.on(file.split(".")[0], event.bind(null, client)); -}; - -client.login(client.config.discord.token); \ No newline at end of file diff --git a/main.js b/main.js new file mode 100644 index 0000000..01a56f2 --- /dev/null +++ b/main.js @@ -0,0 +1,21 @@ +const { Player } = require('discord-player'); +const { Client, Intents } = require('discord.js'); + +global.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'); + +global.player = new Player(client, client.config.opt.discordPlayer); + +require('./src/loader'); +require('./src/events'); + +client.login(client.config.app.token); \ No newline at end of file diff --git a/package.json b/package.json index 39535f9..0108d6c 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,17 @@ { "name": "music-bot", - "main": "index.js", + "main": "main.js", "author": "ZerioDev", - "version": "5.0.0", + "version": "6.0.0", "repository": "https://github.com/ZerioDev/Music-bot.git", - "description": "A complete code to download for a music bot. Using a module (discord-player).", + "description": "A complete code to download for a cool Discord music bot.", "scripts": { - "start": "node index.js" + "start": "node main.js" }, "dependencies": { - "@discordjs/opus": "^0.3.3", - "discord-player": "^3.3.2", - "discord.js": "^12.5.1", - "ffmpeg-static": "^4.2.7" + "discord-player": "^5.1.0", + "discord.js": "^13.1.0", + "ffmpeg-static": "^4.4.0", + "ms": "^3.0.0-canary.1" } -} +} \ No newline at end of file diff --git a/player/botDisconnect.js b/player/botDisconnect.js deleted file mode 100644 index 6e573f7..0000000 --- a/player/botDisconnect.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = (client, message, queue) => { - message.channel.send(`${client.emotes.error} - Music stopped as i have been disconnected from the channel !`); -}; \ No newline at end of file diff --git a/player/channelEmpty.js b/player/channelEmpty.js deleted file mode 100644 index 823300f..0000000 --- a/player/channelEmpty.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = (client, message, queue) => { - message.channel.send(`${client.emotes.error} - Music stopped as there is no more member in the voice channel !`); -}; \ No newline at end of file diff --git a/player/error.js b/player/error.js deleted file mode 100644 index 2a2d096..0000000 --- a/player/error.js +++ /dev/null @@ -1,21 +0,0 @@ -module.exports = (client, error, message, ...args) => { - switch (error) { - case 'NotPlaying': - message.channel.send(`${client.emotes.error} - There is no music being played on this server !`); - break; - case 'NotConnected': - message.channel.send(`${client.emotes.error} - You are not connected in any voice channel !`); - break; - case 'UnableToJoin': - message.channel.send(`${client.emotes.error} - I am not able to join your voice channel, please check my permissions !`); - break; - case 'VideoUnavailable': - message.channel.send(`${client.emotes.error} - ${args[0].title} is not available in your country! Skipping...`); - break; - case 'MusicStarting': - message.channel.send(`The music is starting... please wait and retry!`); - break; - default: - message.channel.send(`${client.emotes.error} - Something went wrong ... Error : ${error}`); - }; -}; diff --git a/player/noResults.js b/player/noResults.js deleted file mode 100644 index 67855f2..0000000 --- a/player/noResults.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = (client, message, query) => { - message.channel.send(`${client.emotes.error} - No results found on YouTube for ${query} !`); -}; \ No newline at end of file diff --git a/player/playlistAdd.js b/player/playlistAdd.js deleted file mode 100644 index aac270f..0000000 --- a/player/playlistAdd.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = (client, message, queue, playlist) => { - message.channel.send(`${client.emotes.music} - ${playlist.title} has been added to the queue (**${playlist.tracks.length}** songs) !`); -}; \ No newline at end of file diff --git a/player/queueEnd.js b/player/queueEnd.js deleted file mode 100644 index 16e0e83..0000000 --- a/player/queueEnd.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = (client, message, queue) => { - message.channel.send(`${client.emotes.error} - Music stopped as there is no more music in the queue !`); -}; \ No newline at end of file diff --git a/player/searchCancel.js b/player/searchCancel.js deleted file mode 100644 index 630e204..0000000 --- a/player/searchCancel.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = (client, message, query, tracks) => { - message.channel.send(`${client.emotes.error} - You did not provide a valid response ... Please send the command again !`); -}; \ No newline at end of file diff --git a/player/searchInvalidResponse.js b/player/searchInvalidResponse.js deleted file mode 100644 index 5cd5f9a..0000000 --- a/player/searchInvalidResponse.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = (client, message, query, tracks, content, collector) => { - if (content === 'cancel') { - collector.stop(); - return message.channel.send(`${client.emotes.success} - The selection has been **cancelled** !`); - } else message.channel.send(`${client.emotes.error} - You must send a valid number between **1** and **${tracks.length}** !`); -}; \ No newline at end of file diff --git a/player/searchResults.js b/player/searchResults.js deleted file mode 100644 index 5c12855..0000000 --- a/player/searchResults.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = (client, message, query, tracks) => { - message.channel.send({ - embed: { - color: 'BLUE', - author: { name: `Here are your search results for ${query}` }, - footer: { text: 'This bot uses a Github project made by Zerio (ZerioDev/Music-bot)' }, - timestamp: new Date(), - description: `${tracks.map((t, i) => `**${i + 1}** - ${t.title}`).join('\n')}`, - }, - }); -}; \ No newline at end of file diff --git a/player/trackAdd.js b/player/trackAdd.js deleted file mode 100644 index 2a5fa74..0000000 --- a/player/trackAdd.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = (client, message, queue, track) => { - message.channel.send(`${client.emotes.music} - ${track.title} has been added to the queue !`); -}; \ No newline at end of file diff --git a/player/trackStart.js b/player/trackStart.js deleted file mode 100644 index d9e9b1b..0000000 --- a/player/trackStart.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = (client, message, track) => { - message.channel.send(`${client.emotes.music} - Now playing ${track.title} into ${message.member.voice.channel.name} ...`); -}; \ No newline at end of file diff --git a/src/events.js b/src/events.js new file mode 100644 index 0000000..3210419 --- /dev/null +++ b/src/events.js @@ -0,0 +1,27 @@ +player.on('error', (queue, error) => { + console.log(`Error emitted from the queue ${error.message}`); +}); + +player.on('connectionError', (queue, error) => { + console.log(`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} added in the queue ✅`); +}); + +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 the voice channel... ❌'); +}); + +player.on('queueEnd', (queue) => { + queue.metadata.send('I finished reading the whole queue ✅'); +}); \ No newline at end of file diff --git a/src/loader.js b/src/loader.js new file mode 100644 index 0000000..9a97674 --- /dev/null +++ b/src/loader.js @@ -0,0 +1,28 @@ +const { readdirSync } = require('fs'); +const { Collection } = require('discord.js'); + +client.commands = new Collection(); + +const events = readdirSync('./events/').filter(file => file.endsWith('.js')); + +console.log(`Loading events...`); + +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(`Loading 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(`-> Loaded command ${command.name.toLowerCase()}`); + client.commands.set(command.name.toLowerCase(), command); + delete require.cache[require.resolve(`../commands/${dirs}/${file}`)]; + }; +}); \ No newline at end of file