diff --git a/.gitignore b/.gitignore index abd417b..ac059c6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ # Node -node_modules/ - +node_modules/ \ No newline at end of file diff --git a/README.md b/README.md index b66e67d..a6e0f04 100644 --- a/README.md +++ b/README.md @@ -8,38 +8,38 @@ If you need help with this project, to get support faster you can join the help ### ⚡ Installation Well, let's start by downloading the code. -Go to the folder `config` then the file `config.json`. +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 : +- For emojis + ```js -{ - "game": "GAME", - "prefix": "PREFIX", - "token_bot": "TOKEN" +emojis: { + off: ':x:', + error: ':warning:', + queue: ':bar_chart:', + music: ':musical_note:', + success: ':white_check_mark:', } ``` -Reminder : +- For configuration -- `game`, the status of the bot. +```js +discord: { + token: 'TOKEN', + prefix: 'PREFIX', + activity: 'ACTIVITY', +} +``` + +- `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. -- `token_bot`, the token of the bot available on the [Discord Developers](https://discordapp.com/developers/applications) section. - -To customize the emojis go to the file `emojis.json`. -Emojis are already defined by default but you can modify them if you wish. - -```js -{ - "music": ":musical_note:", - "queue": ":bar_chart:", - "error": ":x:", - "success": ":white_check_mark:" -} -``` +- `activity`, the activity of the bot. In the console, type `npm install` to install all dependencies. -To start the bot : +- To start the bot : ``` #With Node @@ -55,11 +55,12 @@ All you have to do is turn on your bot ! ### 🎵 Music commands ``` -play , play music in a voice channel. +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, delete the next music. +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. @@ -82,4 +83,4 @@ debug, see number of voice connections. 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). +This is used with [discord.js](https://www.npmjs.com/package/discord.js) and [discord-player](https://www.npmjs.com/package/discord-player). \ No newline at end of file diff --git a/commands/core/help.js b/commands/core/help.js index a9d608f..325dab4 100644 --- a/commands/core/help.js +++ b/commands/core/help.js @@ -6,8 +6,8 @@ module.exports = { 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(', '); + 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(', '); message.channel.send({ embed: { @@ -17,14 +17,14 @@ module.exports = { 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`' }, + { name: 'Filters', value: client.filters.map((x) => '`' + x + '`').join(', ') }, ], timestamp: new Date(), - description: `To use filters, ${client.config.prefix}filter (the filter). Example : ${client.config.prefix}filter 8D.`, + 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(c => c.aliases && c.aliases.includes(args.join(" ").toLowerCase())); + const command = message.client.commands.get(args.join(" ").toLowerCase()) || message.client.commands.find(x => x.aliases && x.aliases.includes(args.join(" ").toLowerCase())); if (!command) return message.channel.send(`${client.emotes.error} - I did not find this command !`); @@ -36,8 +36,8 @@ module.exports = { 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 }, + { 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 `<>`.', diff --git a/commands/infos/debug.js b/commands/infos/debug.js index d90de6d..fb0be53 100644 --- a/commands/infos/debug.js +++ b/commands/infos/debug.js @@ -5,6 +5,6 @@ module.exports = { utilisation: '{prefix}debug', execute(client, message) { - message.channel.send(`${client.emotes.success} - Robot connected in **${client.voice.connections.size}** channels !`); + 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/music/clear-queue.js b/commands/music/clear-queue.js index 7693e35..f1dc858 100644 --- a/commands/music/clear-queue.js +++ b/commands/music/clear-queue.js @@ -7,8 +7,12 @@ module.exports = { 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** !`); diff --git a/commands/music/filter.js b/commands/music/filter.js index 36226f9..b82a692 100644 --- a/commands/music/filter.js +++ b/commands/music/filter.js @@ -7,22 +7,23 @@ module.exports = { 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 (!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()); + const filterToUpdate = client.filters.find((x) => x.toLowerCase() === args[0].toLowerCase()); - if (!filterToUpdate) return message.channel.send(`${client.emotes.error} - This filter doesn't exist !`); + if (!filterToUpdate) return message.channel.send(`${client.emotes.error} - This filter doesn't exist, try for example (8D, vibrato, pulsator...) !`); - 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; + + filtersUpdated[filterToUpdate] = client.player.getQueue(message).filters[filterToUpdate] ? 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.`); + 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.`); }, }; \ No newline at end of file diff --git a/commands/music/loop.js b/commands/music/loop.js index 62b091e..4e39052 100644 --- a/commands/music/loop.js +++ b/commands/music/loop.js @@ -1,20 +1,32 @@ module.exports = { name: 'loop', - aliases: ['lp'], + aliases: ['lp', 'repeat'], category: 'Music', utilisation: '{prefix}loop', - execute(client, message) { + 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 (!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** !`); + 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 !`); + }; } else { - client.player.setRepeatMode(message, true); - return message.channel.send(`${client.emotes.success} - Repeat mode **enabled** !`); + 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 !`); + }; }; }, }; \ No newline at end of file diff --git a/commands/music/nowplaying.js b/commands/music/nowplaying.js index 589d887..4acac1c 100644 --- a/commands/music/nowplaying.js +++ b/commands/music/nowplaying.js @@ -7,14 +7,14 @@ module.exports = { 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 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); - }); + Object.keys(client.player.getQueue(message).filters).forEach((filterName) => client.player.getQueue(message).filters[filterName]) ? filters.push(filterName) : false; message.channel.send({ embed: { @@ -28,7 +28,7 @@ module.exports = { { name: 'Views', value: track.views, inline: true }, { name: 'Duration', value: track.duration, inline: true }, - { name: 'Filters activated', value: filters.length, inline: true }, + { name: 'Filters activated', value: filters.length + '/' + client.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 }, diff --git a/commands/music/pause.js b/commands/music/pause.js index 0214c32..8a44400 100644 --- a/commands/music/pause.js +++ b/commands/music/pause.js @@ -7,12 +7,14 @@ module.exports = { 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).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** !`); + 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 index 5672226..0623a1e 100644 --- a/commands/music/play.js +++ b/commands/music/play.js @@ -7,8 +7,10 @@ module.exports = { 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(" ")); + client.player.play(message, args.join(" "), { firstResult: true }); }, }; \ No newline at end of file diff --git a/commands/music/queue.js b/commands/music/queue.js index a1acf4a..de5af8c 100644 --- a/commands/music/queue.js +++ b/commands/music/queue.js @@ -7,11 +7,13 @@ module.exports = { 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 !`); + 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) => { + 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)...`}`)); }, diff --git a/commands/music/resume.js b/commands/music/resume.js index a3b687a..e3c0000 100644 --- a/commands/music/resume.js +++ b/commands/music/resume.js @@ -7,12 +7,14 @@ module.exports = { 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).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** !`); + 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/search.js b/commands/music/search.js new file mode 100644 index 0000000..bbd501a --- /dev/null +++ b/commands/music/search.js @@ -0,0 +1,16 @@ +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/shuffle.js b/commands/music/shuffle.js index 3b8596b..93f3d1c 100644 --- a/commands/music/shuffle.js +++ b/commands/music/shuffle.js @@ -7,6 +7,8 @@ module.exports = { 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 !`); client.player.shuffle(message); diff --git a/commands/music/skip.js b/commands/music/skip.js index a44eca2..d7f4fd3 100644 --- a/commands/music/skip.js +++ b/commands/music/skip.js @@ -7,6 +7,8 @@ module.exports = { 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 !`); client.player.skip(message); diff --git a/commands/music/stop.js b/commands/music/stop.js index b16c450..57bd31b 100644 --- a/commands/music/stop.js +++ b/commands/music/stop.js @@ -1,12 +1,14 @@ module.exports = { name: 'stop', - aliases: [], + aliases: ['dc'], 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 (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 !`); client.player.setRepeatMode(message, false); diff --git a/commands/music/volume.js b/commands/music/volume.js index 8a9bdb8..80c5729 100644 --- a/commands/music/volume.js +++ b/commands/music/volume.js @@ -7,13 +7,15 @@ module.exports = { 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 (!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 (!args[0] || isNaN(args[0]) || args[0] === 'Infinity') 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]); + client.player.setVolume(message, parseInt(args[0])); message.channel.send(`${client.emotes.success} - Volume set to **${parseInt(args[0])}%** !`); }, diff --git a/commands/music/w-filters.js b/commands/music/w-filters.js index 0f45e44..4771846 100644 --- a/commands/music/w-filters.js +++ b/commands/music/w-filters.js @@ -7,16 +7,15 @@ module.exports = { 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 (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 disabledEmoji = client.emotes.error; - const enabledEmoji = client.emotes.success; + if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); const filtersStatuses = [[], []]; - Object.keys(client.filters).forEach((filterName) => { + 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)); + array.push(filterName.charAt(0).toUpperCase() + filterName.slice(1) + " : " + (client.player.getQueue(message).filters[filterName] ? client.emotes.success : client.emotes.off)); }); message.channel.send({ @@ -28,7 +27,7 @@ module.exports = { { 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.`, + description: `List of all filters enabled or disabled.\nUse \`${client.config.discord.prefix}filter\` to add a filter to a song.`, }, }); }, diff --git a/config/bot.js b/config/bot.js new file mode 100644 index 0000000..f504a11 --- /dev/null +++ b/config/bot.js @@ -0,0 +1,17 @@ +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/config/bot.json b/config/bot.json deleted file mode 100644 index 2cdaa91..0000000 --- a/config/bot.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "game": "GAME", - "prefix": "PREFIX", - "token_bot": "TOKEN" -} \ No newline at end of file diff --git a/config/emojis.json b/config/emojis.json deleted file mode 100644 index 70efdbd..0000000 --- a/config/emojis.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "music": ":musical_note:", - "queue": ":bar_chart:", - "error": ":x:", - "success": ":white_check_mark:" -} diff --git a/config/filters.json b/config/filters.json deleted file mode 100644 index 1a2732f..0000000 --- a/config/filters.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "bassboost": "Bassboost", - "8D": "8D", - "vaporwave": "Vaporwave", - "nightcore": "Nightcore", - "phaser": "Phaser", - "tremolo": "Tremolo", - "vibrato": "Vibrato", - "reverse": "Reverse", - "treble": "Treble", - "normalizer": "Normalizer", - "surrounding": "Surrounding", - "pulsator": "Pulsator", - "subboost": "Subboost", - "karaoke": "Karaoke", - "flanger": "Flanger", - "gate": "Gate", - "haas": "Haas", - "mcompand": "Mcompand" -} diff --git a/events/message.js b/events/message.js index 9ba5fb3..5c685af 100644 --- a/events/message.js +++ b/events/message.js @@ -1,8 +1,7 @@ module.exports = (client, message) => { + if (message.author.bot || message.channel.type === 'dm') return; - if (message.author.bot) return; - - const prefix = client.config.prefix; + const prefix = client.config.discord.prefix; if (message.content.indexOf(prefix) !== 0) return; @@ -12,5 +11,4 @@ module.exports = (client, message) => { 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/ready.js b/events/ready.js index 2716426..bc00202 100644 --- a/events/ready.js +++ b/events/ready.js @@ -1,7 +1,5 @@ module.exports = async (client) => { - console.log(`Ready on ${client.guilds.cache.size} servers, for a total of ${client.users.cache.size} users`); - client.user.setActivity(client.config.game); - + client.user.setActivity(client.config.discord.activity); }; \ No newline at end of file diff --git a/index.js b/index.js index 517ec9c..f5c3c9c 100644 --- a/index.js +++ b/index.js @@ -6,32 +6,20 @@ const client = new discord.Client({ disableMentions: 'everyone' }); const { Player } = require('discord-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.config = require('./config/bot'); +client.emotes = client.config.emojis; +client.filters = client.config.filters; client.commands = new discord.Collection(); -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.readdirSync('./commands').forEach(dirs => { + const commands = fs.readdirSync(`./commands/${dirs}`).filter(files => files.endsWith('.js')); -for (const file of core) { - console.log(`Loading command ${file}`); - const command = require(`./commands/core/${file}`); - client.commands.set(command.name.toLowerCase(), command); -}; - -for (const file of infos) { - console.log(`Loading command ${file}`); - const command = require(`./commands/infos/${file}`); - client.commands.set(command.name.toLowerCase(), command); -}; - -for (const file of music) { - console.log(`Loading command ${file}`); - const command = require(`./commands/music/${file}`); - client.commands.set(command.name.toLowerCase(), command); -}; + 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')); @@ -48,4 +36,4 @@ for (const file of player) { client.player.on(file.split(".")[0], event.bind(null, client)); }; -client.login(client.config.token_bot); \ No newline at end of file +client.login(client.config.discord.token); \ No newline at end of file diff --git a/package.json b/package.json index 8b3a731..cdad3ac 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,18 @@ { "name": "music-bot", - "version": "3.0.0", "main": "index.js", - "repository": "https://github.com/ZerioDev/Music-bot.git", "author": "ZerioDev", "license": "MIT", "scripts": { "start": "node index.js", }, + "version": "5.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).", "dependencies": { - "@discordjs/opus": "^0.3.2", - "discord-player": "^3.0.2", - "discord.js": "^12.2.0", + "@discordjs/opus": "^0.3.3", + "discord-player": "^3.2.0", + "discord.js": "^12.5.1", "ffmpeg-static": "^4.2.7" } } diff --git a/player/playlistAdd.js b/player/playlistAdd.js index e3fa2f4..aac270f 100644 --- a/player/playlistAdd.js +++ b/player/playlistAdd.js @@ -1,3 +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, 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/searchInvalidResponse.js b/player/searchInvalidResponse.js index b640fa8..5cd5f9a 100644 --- a/player/searchInvalidResponse.js +++ b/player/searchInvalidResponse.js @@ -1,3 +1,6 @@ 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}** !`); + 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