From 37f16a51fd5595e3f85a533115cd3929d97f5ec0 Mon Sep 17 00:00:00 2001 From: Marius Begby Date: Mon, 10 Jul 2023 11:41:59 +0200 Subject: [PATCH 1/9] fix: update user reply with info about /play on empty queue --- commands/filters.js | 2 +- commands/pause.js | 2 +- commands/queue.js | 2 +- commands/remove.js | 2 +- commands/skip.js | 2 +- commands/volume.js | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/commands/filters.js b/commands/filters.js index fa2c225..650eaab 100644 --- a/commands/filters.js +++ b/commands/filters.js @@ -37,7 +37,7 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**Failed**\nThere are no tracks in the queue.` + `**Failed**\nThere are no tracks in the queue. Add tracks with \`/play\`!` ) .setColor(embedColors.colorWarning) ] diff --git a/commands/pause.js b/commands/pause.js index 18ce475..acd2cac 100644 --- a/commands/pause.js +++ b/commands/pause.js @@ -27,7 +27,7 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**Failed**\nThere are no tracks in the queue.` + `**Failed**\nThere are no tracks in the queue. Add tracks with \`/play\`!` ) .setColor(embedColors.colorWarning) ] diff --git a/commands/queue.js b/commands/queue.js index d22598f..5bb7626 100644 --- a/commands/queue.js +++ b/commands/queue.js @@ -30,7 +30,7 @@ module.exports = { let queueString = ''; if (!queue) { - queueString = 'There are no tracks in the queue.'; + queueString = 'There are no tracks in the queue. Add tracks with \`/play\`!'; return await interaction.editReply({ embeds: [ new EmbedBuilder() diff --git a/commands/remove.js b/commands/remove.js index b830144..72b1c3f 100644 --- a/commands/remove.js +++ b/commands/remove.js @@ -34,7 +34,7 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**Failed**\nThere are no tracks in the queue.` + `**Failed**\nThere are no tracks in the queue. Add tracks with \`/play\`!` ) .setColor(embedColors.colorWarning) ] diff --git a/commands/skip.js b/commands/skip.js index 7526f30..befc28f 100644 --- a/commands/skip.js +++ b/commands/skip.js @@ -35,7 +35,7 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**Failed**\nThere are no tracks in the queue.` + `**Failed**\nThere are no tracks in the queue. Add tracks with \`/play\`!` ) .setColor(embedColors.colorWarning) ] diff --git a/commands/volume.js b/commands/volume.js index f43f919..57347fe 100644 --- a/commands/volume.js +++ b/commands/volume.js @@ -34,7 +34,7 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**Failed**\nThere are no tracks playing or in the queue.` + `**Failed**\nThere are no tracks playing or in the queue. Add tracks with \`/play\`!` ) .setColor(embedColors.colorWarning) ] From 79956d759a54857202ec84f8ca66e9f108995ef1 Mon Sep 17 00:00:00 2001 From: Marius Begby Date: Mon, 10 Jul 2023 15:00:08 +0200 Subject: [PATCH 2/9] Update discord-player and @discord-player/extractor --- package-lock.json | 26 +++++++++++++------------- package.json | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index 203e982..44ed570 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,11 +9,11 @@ "version": "1.0.2", "license": "MIT", "dependencies": { - "@discord-player/extractor": "^4.3.1", + "@discord-player/extractor": "^4.4.0", "@discordjs/opus": "^0.9.0", "@discordjs/rest": "^1.7.1", "@discordjs/voice": "^0.16.0", - "discord-player": "^6.6.0", + "discord-player": "^6.6.1", "discord.js": "^14.11.0", "play-dl": "^1.9.6" } @@ -24,9 +24,9 @@ "integrity": "sha512-U86em1cMtopXVuKFDxP8J2DcNOqwCAsYQ2tkzPoJvchsrezcI2cgvN3jtGt9FFECP3pLvSz96ZB9FOHZKG5Mqg==" }, "node_modules/@discord-player/extractor": { - "version": "4.3.1", - "resolved": "https://registry.npmjs.org/@discord-player/extractor/-/extractor-4.3.1.tgz", - "integrity": "sha512-f8EwbQkplZQdVb4pCazc+5zo57y4gkPCl4Zq+3nHhwD+lz03OSmFGfoU6Ho9InBbx6S6PthO6CSPyFXN3sH6nw==", + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/@discord-player/extractor/-/extractor-4.4.0.tgz", + "integrity": "sha512-TpHZk6ZFS5ot504iVAfnaJrGe2xv9yMauI+2zNLCmAYPeFe6YUbliXrSRoOmKoZi5n1ahkP2VurbmBhqKqEVkw==", "dependencies": { "file-type": "^16.5.4", "genius-lyrics": "^4.4.3", @@ -43,9 +43,9 @@ "integrity": "sha512-0kW6q4gMQN2B4Z4EzmUgXrKQSXXmyhjdZBBZ/6jSHZ9fh814oOu+JXP01VvtWHwTylI7qJHIctEWtSyjEubCJg==" }, "node_modules/@discord-player/utils": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/@discord-player/utils/-/utils-0.2.1.tgz", - "integrity": "sha512-yPxfdO2N3i2YEEiwlLDNyuBEdnhV1mZaC7im2BI4FKn3ak1UAtVcbKeJhdd/va0A170+PZs3zUKVGldY0z/+ng==", + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/@discord-player/utils/-/utils-0.2.2.tgz", + "integrity": "sha512-UklWUT7BcZEkBgywM9Cmpo2nwj3SQ9Wmhu6ml1uy/YRQnY8IRdZEHD84T2kfjOg4LVZek0ej1VerIqq7a9PAHQ==", "dependencies": { "@discordjs/collection": "^1.1.0" } @@ -490,13 +490,13 @@ "integrity": "sha512-rNif8IAv6duS2z47BMXq/V9kkrLfkAoiwpFY3sLxxbyKprk065zqf3HLTg4bEoxRSmi+Lhc7yqGDrG8C3j8GFA==" }, "node_modules/discord-player": { - "version": "6.6.0", - "resolved": "https://registry.npmjs.org/discord-player/-/discord-player-6.6.0.tgz", - "integrity": "sha512-lW5IcGLycJK6mNtpz5/QqKuhhpBVm475xlsVKEUhoS1CFNcLqob5nAlEXurKjlIhxR+fFglSZ8jmtdFjR8p50g==", + "version": "6.6.1", + "resolved": "https://registry.npmjs.org/discord-player/-/discord-player-6.6.1.tgz", + "integrity": "sha512-l72ql51uya3Uq5VrTPvR6xWBHOa3lI9oWTl7YDDHvofMXEYLgqAuDlyuelQ7AY+lUC7FOK7MoS2QgVFHeAciNw==", "dependencies": { "@discord-player/equalizer": "^0.2.2", "@discord-player/ffmpeg": "^0.1.0", - "@discord-player/utils": "^0.2.1", + "@discord-player/utils": "^0.2.2", "@discordjs/voice": "latest", "libsodium-wrappers": "^0.7.10" }, @@ -504,7 +504,7 @@ "url": "https://github.com/Androz2091/discord-player?sponsor=1" }, "peerDependencies": { - "@discord-player/extractor": "^4.3.1", + "@discord-player/extractor": "^4.4.0", "discord.js": "14.x", "youtube-sr": "4.x" } diff --git a/package.json b/package.json index 9354a08..3ecb01b 100644 --- a/package.json +++ b/package.json @@ -23,11 +23,11 @@ "deploy": "node ./deploy-commands.js && node ./deploy-system-commands.js" }, "dependencies": { - "@discord-player/extractor": "^4.3.1", + "@discord-player/extractor": "^4.4.0", "@discordjs/opus": "^0.9.0", "@discordjs/rest": "^1.7.1", "@discordjs/voice": "^0.16.0", - "discord-player": "^6.6.0", + "discord-player": "^6.6.1", "discord.js": "^14.11.0", "play-dl": "^1.9.6" } From 325feed8fb0e418e1139fb9248986e1d669b9b59 Mon Sep 17 00:00:00 2001 From: Marius Begby Date: Mon, 10 Jul 2023 15:01:18 +0200 Subject: [PATCH 3/9] fix: Explicitly set legacy ffmpeg to false, log loaded dependencies on startup --- index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 8f90e7b..be107a7 100644 --- a/index.js +++ b/index.js @@ -31,7 +31,9 @@ for (const file of systemCommandFiles) { } // Create a new Player, and attach it to the bot client. -const player = new Player(client); +const player = new Player(client, { + useLegacyFFmpeg: false +}); player.events.on('error', (queue, error) => { // Emitted when the player queue encounters error @@ -65,7 +67,8 @@ client.once('ready', async () => { ); // This method will load all the extractors from the @discord-player/extractor package - player.extractors.loadDefault(); + await player.extractors.loadDefault(); + console.log(player.scanDeps()); // Set Discord status client.user.setActivity('/help', { From 31a9d8f034a8091add33cb2f0554beecb66bb789 Mon Sep 17 00:00:00 2001 From: Marius Begby Date: Mon, 10 Jul 2023 16:18:14 +0200 Subject: [PATCH 4/9] fix: Use yt-stream instead of play-dl, solves playback of longer duration yt videoes --- package-lock.json | 23 ++++++----------------- package.json | 2 +- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/package-lock.json b/package-lock.json index 44ed570..8bdcf5c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "@discordjs/voice": "^0.16.0", "discord-player": "^6.6.1", "discord.js": "^14.11.0", - "play-dl": "^1.9.6" + "yt-stream": "^1.4.8" } }, "node_modules/@discord-player/equalizer": { @@ -1026,22 +1026,6 @@ "url": "https://github.com/sponsors/Borewit" } }, - "node_modules/play-audio": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/play-audio/-/play-audio-0.5.2.tgz", - "integrity": "sha512-ZAqHUKkQLix2Iga7pPbsf1LpUoBjcpwU93F1l3qBIfxYddQLhxS6GKmS0d3jV8kSVaUbr6NnOEcEMFvuX93SWQ==" - }, - "node_modules/play-dl": { - "version": "1.9.6", - "resolved": "https://registry.npmjs.org/play-dl/-/play-dl-1.9.6.tgz", - "integrity": "sha512-JW44bQbME9fNfGhGXQ/rdcsHr4BfgJabVlSgpS9QY/NscfprFH1asv+q9atrZThP3+hHIpgtFNABccg9rFWlwg==", - "dependencies": { - "play-audio": "^0.5.2" - }, - "engines": { - "node": ">=16.0.0" - } - }, "node_modules/prism-media": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.3.5.tgz", @@ -1363,6 +1347,11 @@ "version": "4.3.4", "resolved": "https://registry.npmjs.org/youtube-sr/-/youtube-sr-4.3.4.tgz", "integrity": "sha512-olSYcR80XigutCrePEXBX3/RJJrWfonJQj7+/ggBiWU0CzTDLE1q8+lpWTWCG0JpzhzILp/IB/Bq/glGqqr1TQ==" + }, + "node_modules/yt-stream": { + "version": "1.4.8", + "resolved": "https://registry.npmjs.org/yt-stream/-/yt-stream-1.4.8.tgz", + "integrity": "sha512-XtJ1njQ5xKSmW4FAk+YVliyV+XG5/ejAaANUqbyT5ya+COgW9hyswWh16mZJZzj+uEkRobzCId/oH4kP2VmTbQ==" } } } diff --git a/package.json b/package.json index 3ecb01b..f523d54 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,6 @@ "@discordjs/voice": "^0.16.0", "discord-player": "^6.6.1", "discord.js": "^14.11.0", - "play-dl": "^1.9.6" + "yt-stream": "^1.4.8" } } From 981c8ce7c1fba3fbe88a25f71f165f3088325266 Mon Sep 17 00:00:00 2001 From: Marius Begby Date: Mon, 10 Jul 2023 16:18:45 +0200 Subject: [PATCH 5/9] fix: Set max queue and history size --- commands/play.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/commands/play.js b/commands/play.js index f8ef997..00fb7d7 100644 --- a/commands/play.js +++ b/commands/play.js @@ -1,5 +1,5 @@ const { SlashCommandBuilder } = require('@discordjs/builders'); -const { useMainPlayer, useQueue } = require('discord-player'); +const { useMainPlayer } = require('discord-player'); const { EmbedBuilder } = require('discord.js'); const { embedColors } = require('../config.json'); @@ -52,7 +52,9 @@ module.exports = { nodeOptions: { leaveOnEmptyCooldown: 60000, leaveOnEndCooldown: 60000, - leaveOnStopCooldown: 60000 + leaveOnStopCooldown: 60000, + maxSize: 10000, + maxHistorySize: 100 } } ); From 5716c67523c2c2df2433274865e28d2b606e4439 Mon Sep 17 00:00:00 2001 From: Marius Begby Date: Mon, 10 Jul 2023 16:19:12 +0200 Subject: [PATCH 6/9] fix: party solves playback immediately cuts off on longer duration yt videoes --- index.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index be107a7..d154164 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,8 @@ const fs = require('node:fs'); const Discord = require('discord.js'); const { EmbedBuilder } = require('discord.js'); -const { Player } = require('discord-player'); +const { Player, onBeforeCreateStream } = require('discord-player'); +const { stream } = require('yt-stream'); const { token, embedColors } = require('./config.json'); // Setup required permissions for the bot to work @@ -35,6 +36,20 @@ const player = new Player(client, { useLegacyFFmpeg: false }); +onBeforeCreateStream(async (track) => { + if (track.source === 'youtube') { + return ( + await stream(track.url, { + type: 'audio', + quality: 'high', + highWaterMark: 1 << 25 + }) + ).stream; + } + + return null; +}); + player.events.on('error', (queue, error) => { // Emitted when the player queue encounters error console.error( @@ -59,6 +74,12 @@ player.events.on('playerError', (queue, error) => { console.error(error); }); +player.events.on('debug', async (queue, message) => { + // Emitted when the player queue sends debug info + // Useful for seeing what state the current queue is at + console.log(`Player debug event: ${message}`); +}); + client.once('ready', async () => { console.log( `${new Date().toISOString().substring(11, 19)}: Info: Logged in as ${ From 5a476302a8e4b48caf0faa2a21467d375445d58d Mon Sep 17 00:00:00 2001 From: Marius Begby Date: Mon, 10 Jul 2023 17:40:59 +0200 Subject: [PATCH 7/9] fix: remove debug logging --- index.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/index.js b/index.js index d154164..b2e5881 100644 --- a/index.js +++ b/index.js @@ -74,12 +74,6 @@ player.events.on('playerError', (queue, error) => { console.error(error); }); -player.events.on('debug', async (queue, message) => { - // Emitted when the player queue sends debug info - // Useful for seeing what state the current queue is at - console.log(`Player debug event: ${message}`); -}); - client.once('ready', async () => { console.log( `${new Date().toISOString().substring(11, 19)}: Info: Logged in as ${ From f9c4c24d6c91b30782dc57ff6761a4608f298cb1 Mon Sep 17 00:00:00 2001 From: Marius Begby Date: Mon, 10 Jul 2023 17:42:06 +0200 Subject: [PATCH 8/9] fix: formatting --- commands/queue.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/queue.js b/commands/queue.js index 5bb7626..acb9a99 100644 --- a/commands/queue.js +++ b/commands/queue.js @@ -30,7 +30,7 @@ module.exports = { let queueString = ''; if (!queue) { - queueString = 'There are no tracks in the queue. Add tracks with \`/play\`!'; + queueString = `**Failed**\nThere are no tracks in the queue. Add tracks with \`/play\`!`; return await interaction.editReply({ embeds: [ new EmbedBuilder() From 88b95665199c9edfa2edf0ebd551070742be363a Mon Sep 17 00:00:00 2001 From: Marius Begby Date: Mon, 10 Jul 2023 19:36:43 +0200 Subject: [PATCH 9/9] feat: Add playlist support to /play command --- commands/play.js | 115 +++++++++++++++-------------------------------- 1 file changed, 37 insertions(+), 78 deletions(-) diff --git a/commands/play.js b/commands/play.js index 00fb7d7..b2c7008 100644 --- a/commands/play.js +++ b/commands/play.js @@ -29,7 +29,9 @@ module.exports = { const player = useMainPlayer(); const query = interaction.options.getString('query'); - const searchResult = await player.search(query); + const searchResult = await player.search(query, { + requestedBy: interaction.user + }); if (!searchResult || searchResult.tracks.length === 0) { return await interaction.editReply({ @@ -43,22 +45,22 @@ module.exports = { }); } - try { - const { track } = await player.play( - interaction.member.voice.channel, - searchResult.tracks[0].url, - { - requestedBy: interaction.user, - nodeOptions: { - leaveOnEmptyCooldown: 60000, - leaveOnEndCooldown: 60000, - leaveOnStopCooldown: 60000, - maxSize: 10000, - maxHistorySize: 100 - } + const { track } = await player.play( + interaction.member.voice.channel, + searchResult, + { + requestedBy: interaction.user, + nodeOptions: { + leaveOnEmptyCooldown: 60000, + leaveOnEndCooldown: 60000, + leaveOnStopCooldown: 60000, + maxSize: 10000, + maxHistorySize: 100 } - ); + } + ); + if (searchResult.playlist && searchResult.tracks.length > 1) { return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -67,74 +69,31 @@ module.exports = { iconURL: interaction.user.avatarURL() }) .setDescription( - `**Added to queue**\n\`[${track.duration}]\` **[${track.title}](${track.url})**` + `**Added playlist to queue**\n\`[${ + track.duration + }]\` **[${track.title}](${track.url})**\n\nAnd \`${ + searchResult.tracks.length - 1 + }\` more tracks... \`/queue\` to view all.` ) .setThumbnail(track.thumbnail) .setColor(embedColors.colorSuccess) ] }); - } catch (e) { - if (e.message.includes('Could not extract stream for this track')) { - if (searchResult.tracks.length > 1) { - try { - const { track } = await player.play( - interaction.member.voice.channel, - searchResult.tracks[1].url, - { - requestedBy: interaction.user, - nodeOptions: { - leaveOnEmptyCooldown: 60000, - leaveOnEndCooldown: 60000, - leaveOnStopCooldown: 60000 - } - } - ); - - return await interaction.editReply({ - embeds: [ - new EmbedBuilder() - .setAuthor({ - name: interaction.user.username, - iconURL: interaction.user.avatarURL() - }) - .setDescription( - `**Added to queue**\n\`[${track.duration}]\` **[${track.title}](${track.url})**` - ) - .setThumbnail(track.thumbnail) - .setColor(embedColors.colorSuccess) - ] - }); - } catch (e) { - if ( - e.message.includes( - 'Could not extract stream for this track' - ) - ) { - return await interaction.editReply({ - embeds: [ - new EmbedBuilder() - .setDescription( - `**Failed**\nFound a result for query \`${query}\` with source ${searchResult.tracks[1].url}, but was unable to extract audio stream from track.\n\nThis is most likely due to audio source blocking download from the bot. Please try another track or refine your query.` - ) - .setColor(embedColors.colorError) - ] - }); - } - } - } else { - return await interaction.editReply({ - embeds: [ - new EmbedBuilder() - .setDescription( - `**Failed**\nFound a result for query \`${query}\` with source ${searchResult.tracks[0].url}, but was unable to extract audio stream from track.\n\nThis is most likely due to audio source blocking download from the bot or unsupported audio encoding. Please try another track or refine your query.` - ) - .setColor(embedColors.colorError) - ] - }); - } - } else { - throw e; - } } + + return await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setAuthor({ + name: interaction.user.username, + iconURL: interaction.user.avatarURL() + }) + .setDescription( + `**Added to queue**\n\`[${track.duration}]\` **[${track.title}](${track.url})**` + ) + .setThumbnail(track.thumbnail) + .setColor(embedColors.colorSuccess) + ] + }); } };