diff --git a/README.md b/README.md index 80be6e0..ad78a80 100644 --- a/README.md +++ b/README.md @@ -57,23 +57,24 @@ All you have to do is turn on your bot ! play , play music in a voice channel. pause, pause the current music. resume, puts the current music back on. -queue, see the next musics. +queue, see the next songs. clear-queue, delete the next music. shuffle, to mix the queue. -np, see music in progress. +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 filters. +filter , add / remove filter. w-filters, see filters. ``` ### 💡 General commands ``` -help, see the list of available orders. ping, see the bot latency. +help, see the list of available commands. +debug, see number of voice connections. ``` ### 🏓 Utilities (to change the code) diff --git a/commands/clear-queue.js b/commands/clear-queue.js deleted file mode 100644 index 1dea113..0000000 --- a/commands/clear-queue.js +++ /dev/null @@ -1,11 +0,0 @@ -exports.run = async (client, message) => { - - if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); - - if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); - - client.player.clearQueue(message); - - message.channel.send(`${client.emotes.success} - The queue has just been **removed** !`); - -}; diff --git a/commands/core/help.js b/commands/core/help.js new file mode 100644 index 0000000..a9d608f --- /dev/null +++ b/commands/core/help.js @@ -0,0 +1,48 @@ +module.exports = { + name: 'help', + aliases: ['h'], + category: 'Core', + utilisation: '{prefix}help ', + + execute(client, message, args) { + if (!args[0]) { + const infos = message.client.commands.filter(c => c.category == 'Infos').map((c) => '`' + c.name + '`').join(', '); + const music = message.client.commands.filter(c => c.category == 'Music').map((c) => '`' + c.name + '`').join(', '); + + 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: '`bassboost`, `8D`, `vaporwave`, `nightcore`, `phaser`, `tremolo`, `vibrato`, `reverse`, `treble`, `normalizer`, `surrounding`, `pulsator`, `subboost`, `karaoke`, `flanger`, `gate`, `haas`, `mcompand`' }, + ], + timestamp: new Date(), + description: `To use filters, ${client.config.prefix}filter (the filter). Example : ${client.config.prefix}filter 8D.`, + }, + }); + } else { + const command = message.client.commands.get(args.join(" ").toLowerCase()) || message.client.commands.find(c => c.aliases && c.aliases.includes(args.join(" ").toLowerCase())); + + if (!command) return message.channel.send(`${client.emotes.error} - I did not find this command !`); + + 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('\n'), inline: true }, + { name: 'Utilisation', value: command.utilisation.replace('{prefix}', client.config.prefix), inline: true }, + ], + timestamp: new Date(), + description: 'Find information on the command provided.\nMandatory arguments `[]`, optional arguments `<>`.', + } + }); + }; + }, +}; \ No newline at end of file diff --git a/commands/filter.js b/commands/filter.js deleted file mode 100644 index 93cf424..0000000 --- a/commands/filter.js +++ /dev/null @@ -1,23 +0,0 @@ -exports.run = async (client, message, args) => { - - if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); - - if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); - - if (!args[0]) return message.channel.send(`${client.emotes.error} - Please specify a valid filter to enable or disable !`); - - const filterToUpdate = Object.values(client.filters).find((f) => f.toLowerCase() === args[0].toLowerCase()); - - if (!filterToUpdate) return message.channel.send(`${client.emotes.error} - This filter doesn't exist !`); - - const filterRealName = Object.keys(client.filters).find((f) => client.filters[f] === filterToUpdate); - - const queueFilters = client.player.getQueue(message).filters - const filtersUpdated = {}; - filtersUpdated[filterRealName] = queueFilters[filterRealName] ? false : true; - client.player.setFilters(message, filtersUpdated); - - if (filtersUpdated[filterRealName]) 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.`); - -}; diff --git a/commands/help.js b/commands/help.js deleted file mode 100644 index 9f4d6ab..0000000 --- a/commands/help.js +++ /dev/null @@ -1,18 +0,0 @@ -exports.run = async (client, message) => { - - 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: '`ping`' }, - { name: 'Music', value: '`play`, `pause`, `resume`, `queue`, `clear-queue`, `shuffle`, `np`, `loop`, `volume`, `skip`, `stop`, `filter`, `w-filters`' }, - { name: 'Filters', value: '`bassboost`, `8D`, `vaporwave`, `nightcore`, `phaser`, `tremolo`, `vibrato`, `reverse`, `treble`, `normalizer`, `surrounding`, `pulsator`, `subboost`, `karaoke`, `flanger`, `gate`, `haas`, `mcompand`' }, - ], - timestamp: new Date(), - description: `To use filters, ${client.config.prefix}filter (the filter). Example : ${client.config.prefix}filter 8D.`, - }, - }); - -}; diff --git a/commands/infos/debug.js b/commands/infos/debug.js new file mode 100644 index 0000000..d90de6d --- /dev/null +++ b/commands/infos/debug.js @@ -0,0 +1,10 @@ +module.exports = { + name: 'debug', + aliases: [], + category: 'Infos', + utilisation: '{prefix}debug', + + execute(client, message) { + message.channel.send(`${client.emotes.success} - Robot 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 new file mode 100644 index 0000000..19cc447 --- /dev/null +++ b/commands/infos/ping.js @@ -0,0 +1,10 @@ +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/loop.js b/commands/loop.js deleted file mode 100644 index e0f0bac..0000000 --- a/commands/loop.js +++ /dev/null @@ -1,17 +0,0 @@ -exports.run = async (client, message) => { - - if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); - - if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); - - const repeatMode = client.player.getQueue(message).repeatMode; - - if (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** !`); - }; - -}; diff --git a/commands/music/clear-queue.js b/commands/music/clear-queue.js new file mode 100644 index 0000000..7693e35 --- /dev/null +++ b/commands/music/clear-queue.js @@ -0,0 +1,16 @@ +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 (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); + + 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/filter.js b/commands/music/filter.js new file mode 100644 index 0000000..36226f9 --- /dev/null +++ b/commands/music/filter.js @@ -0,0 +1,28 @@ +module.exports = { + name: 'filter', + aliases: [], + category: 'Music', + utilisation: '{prefix}filter [filter name]', + + execute(client, message, args) { + if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); + + if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); + + if (!args[0]) return message.channel.send(`${client.emotes.error} - Please specify a valid filter to enable or disable !`); + + const filterToUpdate = Object.values(client.filters).find((f) => f.toLowerCase() === args[0].toLowerCase()); + + if (!filterToUpdate) return message.channel.send(`${client.emotes.error} - This filter doesn't exist !`); + + const filterRealName = Object.keys(client.filters).find((f) => client.filters[f] === filterToUpdate); + + const queueFilters = client.player.getQueue(message).filters; + const filtersUpdated = {}; + filtersUpdated[filterRealName] = queueFilters[filterRealName] ? false : true; + client.player.setFilters(message, filtersUpdated); + + if (filtersUpdated[filterRealName]) 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.`); + }, +}; \ No newline at end of file diff --git a/commands/music/loop.js b/commands/music/loop.js new file mode 100644 index 0000000..62b091e --- /dev/null +++ b/commands/music/loop.js @@ -0,0 +1,20 @@ +module.exports = { + name: 'loop', + aliases: ['lp'], + category: 'Music', + utilisation: '{prefix}loop', + + execute(client, message) { + if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); + + if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); + + 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** !`); + }; + }, +}; \ No newline at end of file diff --git a/commands/music/nowplaying.js b/commands/music/nowplaying.js new file mode 100644 index 0000000..589d887 --- /dev/null +++ b/commands/music/nowplaying.js @@ -0,0 +1,44 @@ +module.exports = { + name: 'nowplaying', + aliases: ['np'], + category: 'Music', + utilisation: '{prefix}nowplaying', + + execute(client, message) { + if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); + + if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); + + const track = client.player.nowPlaying(message); + const filters = []; + + Object.keys(client.player.getQueue(message).filters).forEach((filterName) => { + if (client.player.getQueue(message).filters[filterName]) filters.push(filterName); + }); + + 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 }, + + { name: 'Views', value: track.views, inline: true }, + { name: 'Duration', value: track.duration, inline: true }, + { name: 'Filters activated', value: filters.length, inline: true }, + + { 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 }, + + { name: 'Progress bar', value: client.player.createProgressBar(message, { timecodes: true }), inline: true } + ], + thumbnail: { url: track.thumbnail }, + timestamp: new Date(), + }, + }); + }, +}; \ No newline at end of file diff --git a/commands/music/pause.js b/commands/music/pause.js new file mode 100644 index 0000000..0214c32 --- /dev/null +++ b/commands/music/pause.js @@ -0,0 +1,18 @@ +module.exports = { + name: 'pause', + aliases: [], + category: 'Music', + utilisation: '{prefix}pause', + + execute(client, message) { + if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); + + if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); + + if (client.player.getQueue(message).paused) return message.channel.send(`${client.emotes.error} - The music is already paused !`); + + client.player.pause(message); + + message.channel.send(`${client.emotes.success} - Song ${client.player.getQueue(message).playing.title} **paused** !`); + }, +}; \ No newline at end of file diff --git a/commands/music/play.js b/commands/music/play.js new file mode 100644 index 0000000..5672226 --- /dev/null +++ b/commands/music/play.js @@ -0,0 +1,14 @@ +module.exports = { + name: 'play', + aliases: ['p'], + category: 'Music', + utilisation: '{prefix}play [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 (!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/queue.js b/commands/music/queue.js new file mode 100644 index 0000000..a1acf4a --- /dev/null +++ b/commands/music/queue.js @@ -0,0 +1,18 @@ +module.exports = { + name: 'queue', + aliases: [], + category: 'Music', + utilisation: '{prefix}queue', + + execute(client, message) { + if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); + + const queue = client.player.getQueue(message); + + if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No songs currently playing !`); + + message.channel.send(`**Server queue - ${message.guild.name} ${client.emotes.queue}**\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)...`}`)); + }, +}; \ No newline at end of file diff --git a/commands/music/resume.js b/commands/music/resume.js new file mode 100644 index 0000000..a3b687a --- /dev/null +++ b/commands/music/resume.js @@ -0,0 +1,18 @@ +module.exports = { + name: 'resume', + aliases: [], + category: 'Music', + utilisation: '{prefix}resume', + + execute(client, message) { + if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); + + if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); + + if (!client.player.getQueue(message).paused) return message.channel.send(`${client.emotes.error} - The music is already playing !`); + + client.player.resume(message); + + message.channel.send(`${client.emotes.success} - Song ${client.player.getQueue(message).playing.title} **resumed** !`); + }, +}; \ No newline at end of file diff --git a/commands/music/shuffle.js b/commands/music/shuffle.js new file mode 100644 index 0000000..3b8596b --- /dev/null +++ b/commands/music/shuffle.js @@ -0,0 +1,16 @@ +module.exports = { + name: 'shuffle', + aliases: ['sh'], + category: 'Music', + utilisation: '{prefix}shuffle', + + execute(client, message) { + if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); + + if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); + + client.player.shuffle(message); + + return message.channel.send(`${client.emotes.success} - Queue shuffled **${client.player.getQueue(message).tracks.length}** song(s) !`); + }, +}; \ No newline at end of file diff --git a/commands/music/skip.js b/commands/music/skip.js new file mode 100644 index 0000000..a44eca2 --- /dev/null +++ b/commands/music/skip.js @@ -0,0 +1,16 @@ +module.exports = { + name: 'skip', + aliases: ['sk'], + category: 'Music', + utilisation: '{prefix}skip', + + execute(client, message) { + if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); + + if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); + + client.player.skip(message); + + message.channel.send(`${client.emotes.success} - The current music has just been **skipped** !`); + }, +}; \ No newline at end of file diff --git a/commands/music/stop.js b/commands/music/stop.js new file mode 100644 index 0000000..b16c450 --- /dev/null +++ b/commands/music/stop.js @@ -0,0 +1,17 @@ +module.exports = { + name: 'stop', + aliases: [], + category: 'Music', + utilisation: '{prefix}stop', + + execute(client, message) { + if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); + + if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); + + client.player.setRepeatMode(message, false); + client.player.stop(message); + + message.channel.send(`${client.emotes.success} - Music **stopped** into this server !`); + }, +}; \ No newline at end of file diff --git a/commands/music/volume.js b/commands/music/volume.js new file mode 100644 index 0000000..8a9bdb8 --- /dev/null +++ b/commands/music/volume.js @@ -0,0 +1,20 @@ +module.exports = { + name: 'volume', + aliases: [], + category: 'Music', + utilisation: '{prefix}volume [1-100]', + + execute(client, message, args) { + if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); + + if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); + + if (!args[0] || isNaN(args[0])) return message.channel.send(`${client.emotes.error} - Please enter a valid number !`); + + 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) !`); + + client.player.setVolume(message, args[0]); + + message.channel.send(`${client.emotes.success} - Volume set to **${parseInt(args[0])}%** !`); + }, +}; \ No newline at end of file diff --git a/commands/music/w-filters.js b/commands/music/w-filters.js new file mode 100644 index 0000000..0f45e44 --- /dev/null +++ b/commands/music/w-filters.js @@ -0,0 +1,35 @@ +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 (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); + + const disabledEmoji = client.emotes.error; + const enabledEmoji = client.emotes.success; + + const filtersStatuses = [[], []]; + + Object.keys(client.filters).forEach((filterName) => { + const array = filtersStatuses[0].length > filtersStatuses[1].length ? filtersStatuses[1] : filtersStatuses[0]; + array.push(client.filters[filterName] + " : " + (client.player.getQueue(message).filters[filterName] ? enabledEmoji : disabledEmoji)); + }); + + 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.prefix}filter\` to add a filter to a song.`, + }, + }); + }, +}; \ No newline at end of file diff --git a/commands/np.js b/commands/np.js deleted file mode 100644 index e100b99..0000000 --- a/commands/np.js +++ /dev/null @@ -1,35 +0,0 @@ -exports.run = async (client, message) => { - - if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); - - if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); - - const track = await client.player.nowPlaying(message); - const filters = []; - - Object.keys(client.player.getQueue(message).filters).forEach((filterName) => { - if (client.player.getQueue(message).filters[filterName]) filters.push(filterName); - }); - - 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 }, - - { name: 'Views', value: track.views, inline: true }, - { name: 'Duration', value: track.duration, inline: true }, - { name: 'Filters activated', value: filters.length, inline: true }, - - { name: 'Progress bar', value: client.player.createProgressBar(message, { timecodes: true }), inline: true } - ], - thumbnail: { url: track.thumbnail }, - timestamp: new Date(), - }, - }); - -}; diff --git a/commands/pause.js b/commands/pause.js deleted file mode 100644 index 3adca02..0000000 --- a/commands/pause.js +++ /dev/null @@ -1,11 +0,0 @@ -exports.run = async (client, message) => { - - if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); - - if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); - - client.player.pause(message); - - message.channel.send(`${client.emotes.success} - Song ${client.player.getQueue(message).playing.title} **paused** !`); - -}; diff --git a/commands/ping.js b/commands/ping.js deleted file mode 100644 index 549acec..0000000 --- a/commands/ping.js +++ /dev/null @@ -1,5 +0,0 @@ -exports.run = async (client, message) => { - - message.channel.send(`${client.emotes.success} - Ping : **${client.ws.ping}ms** !`); - -}; diff --git a/commands/play.js b/commands/play.js deleted file mode 100644 index 0c2ab69..0000000 --- a/commands/play.js +++ /dev/null @@ -1,9 +0,0 @@ -exports.run = async (client, message, args) => { - - if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a 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(" ")); - -}; diff --git a/commands/queue.js b/commands/queue.js deleted file mode 100644 index 0aca5a7..0000000 --- a/commands/queue.js +++ /dev/null @@ -1,13 +0,0 @@ -exports.run = async (client, message) => { - - if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); - - const queue = client.player.getQueue(message); - - if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No songs currently playing !`); - - message.channel.send(`**Server queue - ${message.guild.name} ${client.emotes.queue}**\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)...`}`)); - -}; diff --git a/commands/resume.js b/commands/resume.js deleted file mode 100644 index 2d59afd..0000000 --- a/commands/resume.js +++ /dev/null @@ -1,11 +0,0 @@ -exports.run = async (client, message) => { - - if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); - - if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); - - client.player.resume(message); - - message.channel.send(`${client.emotes.success} - Song ${client.player.getQueue(message).playing.title} **resumed** !`); - -}; diff --git a/commands/shuffle.js b/commands/shuffle.js deleted file mode 100644 index ec72a96..0000000 --- a/commands/shuffle.js +++ /dev/null @@ -1,11 +0,0 @@ -exports.run = async (client, message) => { - - if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); - - if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); - - client.player.shuffle(message); - - return message.channel.send(`${client.emotes.success} - Queue shuffled **${client.player.getQueue(message).tracks.length}** song(s) !`); - -}; diff --git a/commands/skip.js b/commands/skip.js deleted file mode 100644 index e19fcd6..0000000 --- a/commands/skip.js +++ /dev/null @@ -1,11 +0,0 @@ -exports.run = async (client, message) => { - - if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); - - if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); - - client.player.skip(message); - - message.channel.send(`${client.emotes.success} - The current music has just been **skipped** !`); - -}; diff --git a/commands/stop.js b/commands/stop.js deleted file mode 100644 index 658b999..0000000 --- a/commands/stop.js +++ /dev/null @@ -1,12 +0,0 @@ -exports.run = async (client, message) => { - - if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); - - if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); - - client.player.setRepeatMode(message, false); - client.player.stop(message); - - message.channel.send(`${client.emotes.success} - Music **stopped** into this server !`); - -}; diff --git a/commands/volume.js b/commands/volume.js deleted file mode 100644 index 6f51a9d..0000000 --- a/commands/volume.js +++ /dev/null @@ -1,17 +0,0 @@ -exports.run = async (client, message, args) => { - - if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); - - if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); - - if (!args[0]) return message.channel.send(`${client.emotes.error} - Please enter a number !`); - - if (isNaN(args[0]) || 100 < args[0] || args[0] <= 0) return message.channel.send(`${client.emotes.error} - Please enter a valid number (between 1 and 100) !`); - - if (message.content.includes('-') || message.content.includes('+') || message.content.includes(',') || message.content.includes('.')) return message.channel.send(`${client.emotes.error} - Please enter a valid number !`); - - client.player.setVolume(message, parseInt(args[0])); - - message.channel.send(`${client.emotes.success} - Volume set to **${args.join(" ")}%** !`); - -}; diff --git a/commands/w-filters.js b/commands/w-filters.js deleted file mode 100644 index fbef4ea..0000000 --- a/commands/w-filters.js +++ /dev/null @@ -1,30 +0,0 @@ -exports.run = async (client, message) => { - - if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`); - - if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); - - const disabledEmoji = client.emotes.error; - const enabledEmoji = client.emotes.success; - - const filtersStatuses = [[], []]; - - Object.keys(client.filters).forEach((filterName) => { - const array = filtersStatuses[0].length > filtersStatuses[1].length ? filtersStatuses[1] : filtersStatuses[0]; - array.push(client.filters[filterName] + " : " + (client.player.getQueue(message).filters[filterName] ? enabledEmoji : disabledEmoji)); - }); - - 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.prefix}filter\` to add a filter to a song.`, - }, - }); - -}; diff --git a/config/bot.json b/config/bot.json index b8624aa..2cdaa91 100644 --- a/config/bot.json +++ b/config/bot.json @@ -2,4 +2,4 @@ "game": "GAME", "prefix": "PREFIX", "token_bot": "TOKEN" -} +} \ No newline at end of file diff --git a/events/message.js b/events/message.js index 3763445..9ba5fb3 100644 --- a/events/message.js +++ b/events/message.js @@ -9,10 +9,8 @@ module.exports = (client, message) => { const args = message.content.slice(prefix.length).trim().split(/ +/g); const command = args.shift().toLowerCase(); - const cmd = client.commands.get(command); + const cmd = client.commands.get(command) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(command)); - if (!cmd) return; + if (cmd) cmd.execute(client, message, args); - cmd.run(client, message, args); - -}; +}; \ No newline at end of file diff --git a/events/ready.js b/events/ready.js index 5d7be01..2716426 100644 --- a/events/ready.js +++ b/events/ready.js @@ -4,4 +4,4 @@ module.exports = async (client) => { client.user.setActivity(client.config.game); -}; +}; \ No newline at end of file diff --git a/index.js b/index.js index fe17d76..517ec9c 100644 --- a/index.js +++ b/index.js @@ -5,42 +5,47 @@ const client = new discord.Client({ disableMentions: 'everyone' }); const { Player } = require('discord-player'); -const player = new Player(client); -client.player = player; +client.player = new Player(client); client.config = require('./config/bot.json'); client.emotes = require('./config/emojis.json'); client.filters = require('./config/filters.json'); client.commands = new discord.Collection(); -fs.readdir('./events/', (err, files) => { - if (err) return console.error(err); - files.forEach(file => { - const event = require(`./events/${file}`); - let eventName = file.split(".")[0]; - console.log(`Loading event ${eventName}`); - client.on(eventName, event.bind(null, client)); - }); -}); +const core = fs.readdirSync('./commands/core').filter(file => file.endsWith('.js')); +const infos = fs.readdirSync('./commands/infos').filter(file => file.endsWith('.js')); +const music = fs.readdirSync('./commands/music').filter(file => file.endsWith('.js')); -fs.readdir('./player-events/', (err, files) => { - if (err) return console.error(err); - files.forEach(file => { - const event = require(`./player-events/${file}`); - let eventName = file.split(".")[0]; - console.log(`Loading player event ${eventName}`); - client.player.on(eventName, event.bind(null, client)); - }); -}); +for (const file of core) { + console.log(`Loading command ${file}`); + const command = require(`./commands/core/${file}`); + client.commands.set(command.name.toLowerCase(), command); +}; -fs.readdir('./commands/', (err, files) => { - if (err) return console.error(err); - files.forEach(file => { - if (!file.endsWith(".js")) return; - let props = require(`./commands/${file}`); - let commandName = file.split(".")[0]; - console.log(`Loading command ${commandName}`); - client.commands.set(commandName, props); - }); -}); +for (const file of infos) { + console.log(`Loading command ${file}`); + const command = require(`./commands/infos/${file}`); + client.commands.set(command.name.toLowerCase(), command); +}; -client.login(client.config.token_bot); +for (const file of music) { + console.log(`Loading command ${file}`); + const command = require(`./commands/music/${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.token_bot); \ No newline at end of file diff --git a/package.json b/package.json index 16abd04..6ae45ae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "music-bot", - "version": "2.0.1", + "version": "3.0.0", "main": "index.js", "repository": "https://github.com/ZerioDev/Music-bot.git", "author": "ZerioDev", @@ -11,4 +11,4 @@ "discord.js": "^12.2.0", "ffmpeg-static": "^4.2.7" } -} +} \ No newline at end of file diff --git a/player-events/botDisconnect.js b/player/botDisconnect.js similarity index 97% rename from player-events/botDisconnect.js rename to player/botDisconnect.js index e502fc9..6e573f7 100644 --- a/player-events/botDisconnect.js +++ b/player/botDisconnect.js @@ -1,5 +1,3 @@ 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-events/channelEmpty.js b/player/channelEmpty.js similarity index 96% rename from player-events/channelEmpty.js rename to player/channelEmpty.js index 7a89a8f..823300f 100644 --- a/player-events/channelEmpty.js +++ b/player/channelEmpty.js @@ -1,5 +1,3 @@ -module.exports = (client, message, queue) => { - - message.channel.send(`${client.emotes.error} - Music stopped as there is no more member in the voice channel !`); - +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-events/error.js b/player/error.js similarity index 97% rename from player-events/error.js rename to player/error.js index b5b05da..99382fc 100644 --- a/player-events/error.js +++ b/player/error.js @@ -1,17 +1,15 @@ -module.exports = (client, error, message) => { - - 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; - default: - message.channel.send(`${client.emotes.error} - Something went wrong ... Error : ${error}`); - }; - -}; +module.exports = (client, error, message) => { + 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; + default: + message.channel.send(`${client.emotes.error} - Something went wrong ... Error : ${error}`); + }; +}; diff --git a/player-events/noResults.js b/player/noResults.js similarity index 96% rename from player-events/noResults.js rename to player/noResults.js index 5a23c87..67855f2 100644 --- a/player-events/noResults.js +++ b/player/noResults.js @@ -1,5 +1,3 @@ -module.exports = (client, message, query) => { - - message.channel.send(`${client.emotes.error} - No results found on YouTube for ${query} !`); - +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-events/playlistAdd.js b/player/playlistAdd.js similarity index 96% rename from player-events/playlistAdd.js rename to player/playlistAdd.js index 74eeb74..e3fa2f4 100644 --- a/player-events/playlistAdd.js +++ b/player/playlistAdd.js @@ -1,5 +1,3 @@ -module.exports = (client, message, playlist) => { - - message.channel.send(`${client.emotes.music} - ${playlist.title} has been added to the queue (**${playlist.items.length}** songs) !`); - +module.exports = (client, message, playlist) => { + message.channel.send(`${client.emotes.music} - ${playlist.title} has been added to the queue (**${playlist.items.length}** songs) !`); }; \ No newline at end of file diff --git a/player-events/queueEnd.js b/player/queueEnd.js similarity index 96% rename from player-events/queueEnd.js rename to player/queueEnd.js index dc95920..16e0e83 100644 --- a/player-events/queueEnd.js +++ b/player/queueEnd.js @@ -1,5 +1,3 @@ -module.exports = (client, message, queue) => { - - message.channel.send(`${client.emotes.error} - Music stopped as there is no more music in the queue !`); - +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-events/searchCancel.js b/player/searchCancel.js similarity index 96% rename from player-events/searchCancel.js rename to player/searchCancel.js index 7ad0978..630e204 100644 --- a/player-events/searchCancel.js +++ b/player/searchCancel.js @@ -1,5 +1,3 @@ -module.exports = (client, message, query, tracks) => { - - message.channel.send(`${client.emotes.error} - You did not provide a valid response ... Please send the command again !`); - +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-events/searchInvalidResponse.js b/player/searchInvalidResponse.js similarity index 97% rename from player-events/searchInvalidResponse.js rename to player/searchInvalidResponse.js index de03d6e..b640fa8 100644 --- a/player-events/searchInvalidResponse.js +++ b/player/searchInvalidResponse.js @@ -1,5 +1,3 @@ -module.exports = (client, message, query, tracks, content, collector) => { - - message.channel.send(`${client.emotes.error} - You must send a valid number between **1** and **${tracks.length}** !`); - +module.exports = (client, message, query, tracks, content, collector) => { + 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-events/searchResults.js b/player/searchResults.js similarity index 96% rename from player-events/searchResults.js rename to player/searchResults.js index 47242c6..5c12855 100644 --- a/player-events/searchResults.js +++ b/player/searchResults.js @@ -1,13 +1,11 @@ -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')}`, - }, - }); - +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-events/trackAdd.js b/player/trackAdd.js similarity index 96% rename from player-events/trackAdd.js rename to player/trackAdd.js index e43ef02..2a5fa74 100644 --- a/player-events/trackAdd.js +++ b/player/trackAdd.js @@ -1,5 +1,3 @@ -module.exports = (client, message, queue, track) => { - - message.channel.send(`${client.emotes.music} - ${track.title} has been added to the queue !`); - +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-events/trackStart.js b/player/trackStart.js similarity index 96% rename from player-events/trackStart.js rename to player/trackStart.js index 9d1b024..d9e9b1b 100644 --- a/player-events/trackStart.js +++ b/player/trackStart.js @@ -1,5 +1,3 @@ -module.exports = (client, message, track) => { - - message.channel.send(`${client.emotes.music} - Now playing ${track.title} into ${message.member.voice.channel.name} ...`); - +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