diff --git a/README.md b/README.md index 178facc..31ffced 100644 --- a/README.md +++ b/README.md @@ -54,11 +54,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. diff --git a/commands/music/clear-queue.js b/commands/music/clear-queue.js index d9dbd37..f1dc858 100644 --- a/commands/music/clear-queue.js +++ b/commands/music/clear-queue.js @@ -11,6 +11,8 @@ module.exports = { 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/loop.js b/commands/music/loop.js index bde42b1..4e39052 100644 --- a/commands/music/loop.js +++ b/commands/music/loop.js @@ -4,19 +4,29 @@ module.exports = { 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/play.js b/commands/music/play.js index 30341ce..0623a1e 100644 --- a/commands/music/play.js +++ b/commands/music/play.js @@ -11,6 +11,6 @@ module.exports = { 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 2381dbd..de5af8c 100644 --- a/commands/music/queue.js +++ b/commands/music/queue.js @@ -13,7 +13,7 @@ module.exports = { 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/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/volume.js b/commands/music/volume.js index 0d84115..80c5729 100644 --- a/commands/music/volume.js +++ b/commands/music/volume.js @@ -15,7 +15,7 @@ module.exports = { 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/package.json b/package.json index 92aeded..4349415 100644 --- a/package.json +++ b/package.json @@ -2,13 +2,13 @@ "name": "music-bot", "main": "index.js", "author": "ZerioDev", - "version": "4.0.2", + "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.3", - "discord-player": "^3.0.3", + "discord-player": "^3.2.0", "discord.js": "^12.5.1", "ffmpeg-static": "^4.2.7" } -} +} \ No newline at end of file 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