diff --git a/commands/filters.js b/commands/filters.js index adad394..0ffbc2e 100644 --- a/commands/filters.js +++ b/commands/filters.js @@ -25,7 +25,7 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - '**Failed**\nYou need to be in a voice channel to use this command.' + `**${embedIcons.warning} Oops!**\nYou need to be in a voice channel to use this command.` ) .setColor(embedColors.colorWarning) ] @@ -39,7 +39,7 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - '**Failed**\nThere are no tracks in the queue. Add tracks with `/play`!' + `**${embedIcons.warning} Oops!**\nThere are no tracks in the queue. First add some tracks with \`/play\`!` ) .setColor(embedColors.colorWarning) ] @@ -81,13 +81,14 @@ module.exports = { .setCustomId('disable-filters') .setLabel('Disable all filters') .setStyle('Secondary') + .setEmoji(embedIcons.disable) ); const response = await interaction.editReply({ embeds: [ new EmbedBuilder() .setDescription( - `**Toggle filters** ${embedIcons.beta}\nToggle or disable audio filters for playback.` + `**Toggle filters** ${embedIcons.beta}\nEnable or disable audio filters for playback from the menu.` ) .setColor(embedColors.colorInfo) ], @@ -124,7 +125,7 @@ module.exports = { confirmation.customId === 'disable-filters' || confirmation.values.length === 0 ) { - return interaction.editReply({ + return await interaction.editReply({ embeds: [ new EmbedBuilder() .setAuthor({ @@ -132,7 +133,7 @@ module.exports = { iconURL: interaction.user.avatarURL() }) .setDescription( - '**Disabled filters**\nDisabled all audio filters.' + `**${embedIcons.success} Disabled filters**\nAll audio filters have been disabled.` ) .setColor(embedColors.colorSuccess) ], @@ -151,7 +152,9 @@ module.exports = { iconURL: interaction.user.avatarURL() }) .setDescription( - `**Filters enabled**\nThese filters are now enabled:\n${confirmation.values + `**${ + embedIcons.success + } Filters toggled**\nNow using these filters:\n${confirmation.values .map( (enabled) => `\`${ diff --git a/commands/help.js b/commands/help.js index aef6567..29a6c58 100644 --- a/commands/help.js +++ b/commands/help.js @@ -13,18 +13,17 @@ module.exports = { new EmbedBuilder() .setDescription( `${embedIcons.rule} **List of commands**\n` + - '`/help` - Show this menu.\n' + - '`/play` `query` - Add a track or playlist to the queue by searching or url.\n' + - '`/pause` - Pause or resume the current track.\n' + - '`/queue` `[page]` - Show the list of tracks added to the queue.\n' + - '`/nowplaying` - Show information about the track currently playing.\n' + - '`/filters` - Toggle various audio filters during playback.\n' + - '`/volume` `[percentage]` - Show or set the playback volume for tracks.\n' + - '`/skip` `[trackNumber]` - Skip the current track.\n' + - '`/remove` `trackNumber` - Remove a specific track from the queue.\n' + - '`/leave` - Remove bot from voice channel and clear the queue.\n\n' + - `${embedIcons.support} **Support server**\nJoin the support server for help or suggestions: \n${botInfo.supportServerInviteUrl}\n\n` + - `${embedIcons.bot} **Invite the bot**\nAdd me to another server: \n[Click me!](${botInfo.botInviteUrl})` + '- `/play` `query` - Add a track or playlist to the queue by searching or url.\n' + + '- `/pause` - Pause or resume the current track.\n' + + '- `/queue` `[page]` - Show the list of tracks added to the queue.\n' + + `- \`/nowplaying\` - ${embedIcons.new} Show information about the track currently playing.\n` + + `- \`/filters\` - ${embedIcons.beta} Toggle various audio filters during playback.\n` + + '- `/volume` `[percentage]` - Show or set the playback volume for tracks.\n' + + '- `/skip` `[trackNumber]` - Skip current or specified track.\n' + + '- `/remove` `trackNumber` - Remove a specific track from the queue.\n' + + '- `/leave` - Clear the track queue and remove the bot from voice channel.\n\n' + + `${embedIcons.support} **Support server**\nJoin the support server for help or suggestions: \n**${botInfo.supportServerInviteUrl}**\n\n` + + `${embedIcons.bot} **Enjoying ${botInfo.name}?**\nAdd me to another server: \n**[Click me!](${botInfo.botInviteUrl})**` ) .setColor(embedColors.colorInfo) ] diff --git a/commands/leave.js b/commands/leave.js index 1f23e79..8985577 100644 --- a/commands/leave.js +++ b/commands/leave.js @@ -1,7 +1,7 @@ const { SlashCommandBuilder } = require('@discordjs/builders'); const { useQueue } = require('discord-player'); const { EmbedBuilder } = require('discord.js'); -const { embedColors } = require('../config.json'); +const { embedColors, embedIcons } = require('../config.json'); module.exports = { data: new SlashCommandBuilder() @@ -18,7 +18,7 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - '**Failed**\nYou need to be in a voice channel to use this command.' + `**${embedIcons.warning} Oops!**\nYou need to be in a voice channel to use this command.` ) .setColor(embedColors.colorWarning) ] @@ -32,7 +32,7 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - '**Failed**\nNo tracks are currently playing, and the queue is empty. Use the `/play` command to play some music!' + `**${embedIcons.warning} Oops!**\n_Hmm.._ It seems I am already not in a voice channel!` ) .setColor(embedColors.colorWarning) ] @@ -46,7 +46,7 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - '**Leaving**\nCleared the track queue and left voice channel. To play more music, use the `/play` command!' + `**${embedIcons.success} Leaving channel**\nCleared the track queue and left voice channel. To play more music, use the \`/play\` command!` ) .setColor(embedColors.colorSuccess) ] diff --git a/commands/nowplaying.js b/commands/nowplaying.js index b2ef645..fbbc4ff 100644 --- a/commands/nowplaying.js +++ b/commands/nowplaying.js @@ -1,7 +1,11 @@ const { SlashCommandBuilder } = require('@discordjs/builders'); const { useQueue } = require('discord-player'); const { EmbedBuilder, ActionRowBuilder, ButtonBuilder } = require('discord.js'); -const { embedColors, progressBarOptions } = require('../config.json'); +const { + embedColors, + embedIcons, + progressBarOptions +} = require('../config.json'); module.exports = { data: new SlashCommandBuilder() @@ -14,7 +18,7 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - '**Failed**\nYou need to be in a voice channel to use this command.' + `**${embedIcons.warning} Oops!**\nYou need to be in a voice channel to use this command.` ) .setColor(embedColors.colorWarning) ] @@ -28,7 +32,7 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - '**Failed**\nThere are no tracks in the queue. Add tracks with `/play`!' + `**${embedIcons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with \`/play\`!` ) .setColor(embedColors.colorWarning) ] @@ -40,7 +44,7 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - '**Failed**\nThere are no tracks in the queue or currently playing.' + `**${embedIcons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with \`/play\`!` ) .setColor(embedColors.colorWarning) ] @@ -56,13 +60,15 @@ module.exports = { ]); const currentTrack = queue.currentTrack; - let author = currentTrack.author ? currentTrack.author : 'Unknown'; + let author = currentTrack.author ? currentTrack.author : 'Unavailable'; if (author === 'cdn.discordapp.com') { - author = 'Unknown'; + author = 'Unavailable'; } - const plays = currentTrack.views !== 0 ? currentTrack.views : 'Unknown'; + const plays = + currentTrack.views !== 0 ? currentTrack.views : 'Unavailable'; const source = - sourceStringsFormatted.get(currentTrack.raw.source) ?? 'Unknown'; + sourceStringsFormatted.get(currentTrack.raw.source) ?? + 'Unavailable'; const queueLength = queue.tracks.data.length; const timestamp = queue.node.getTimestamp(); let bar = `\`${ @@ -88,6 +94,7 @@ module.exports = { .setCustomId('nowplaying-skip') .setLabel('Skip track') .setStyle('Secondary') + .setEmoji(embedIcons.nextTrack) ); const response = await interaction.editReply({ @@ -102,7 +109,7 @@ module.exports = { .setDescription( (queue.node.isPaused() ? '**Currently Paused**\n' - : '**Now Playing**\n') + + : `**${embedIcons.audioPlaying} Now Playing**\n`) + (currentTrack ? `**[${currentTrack.title}](${currentTrack.url})**` : 'None') + @@ -122,7 +129,7 @@ module.exports = { }, { name: '**Audio source**', - value: `[${source}](${currentTrack.url})`, + value: `**[${source}](${currentTrack.url})**`, inline: true } ) @@ -132,7 +139,7 @@ module.exports = { : ' ' }) .setThumbnail(queue.currentTrack.thumbnail) - .setColor(embedColors.colorSuccess) + .setColor(embedColors.colorInfo) ], components: [nowPlayingActionRow] }); @@ -155,7 +162,7 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - '**Failed**\nThere are no tracks in the queue and nothing currently playing.' + `**${embedIcons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with \`/play\`!` ) .setColor(embedColors.colorWarning) ], @@ -168,7 +175,7 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - '**Failed to skip**\nThis track has already been skipped, or is no longer playing.' + '**${embedIcons.warning} Oops!**\nThis track has already been skipped or is no longer playing.' ) .setColor(embedColors.colorWarning) ], @@ -192,7 +199,7 @@ module.exports = { iconURL: interaction.user.avatarURL() }) .setDescription( - `**Skipped track**\n${durationFormat} **[${skippedTrack.title}](${skippedTrack.url})**.` + `**${embedIcons.skipped} Skipped track**\n${durationFormat} **[${skippedTrack.title}](${skippedTrack.url})**.` ) .setThumbnail(skippedTrack.thumbnail) .setColor(embedColors.colorSuccess) diff --git a/commands/pause.js b/commands/pause.js index d306427..39cb8bc 100644 --- a/commands/pause.js +++ b/commands/pause.js @@ -1,7 +1,7 @@ const { SlashCommandBuilder } = require('@discordjs/builders'); const { useQueue } = require('discord-player'); const { EmbedBuilder } = require('discord.js'); -const { embedColors } = require('../config.json'); +const { embedColors, embedIcons } = require('../config.json'); module.exports = { data: new SlashCommandBuilder() @@ -14,7 +14,7 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - '**Failed**\nYou need to be in a voice channel to use this command.' + `**${embedIcons.warning} Oops!**\nYou need to be in a voice channel to use this command.` ) .setColor(embedColors.colorWarning) ] @@ -28,7 +28,7 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - '**Failed**\nThere are no tracks in the queue. Add tracks with `/play`!' + `**${embedIcons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with \`/play\`!` ) .setColor(embedColors.colorWarning) ] @@ -40,7 +40,7 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - '**Failed**\nThere are no tracks in the queue or currently playing.' + `**${embedIcons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with \`/play\`!` ) .setColor(embedColors.colorWarning) ] @@ -59,7 +59,7 @@ module.exports = { iconURL: interaction.user.avatarURL() }) .setDescription( - `**Paused**\n**[${queue.currentTrack.title}](${queue.currentTrack.url})**.` + `**${embedIcons.pauseResumed} Paused track**\n**[${queue.currentTrack.title}](${queue.currentTrack.url})**.` ) .setThumbnail(queue.currentTrack.thumbnail) .setColor(embedColors.colorSuccess) @@ -74,7 +74,7 @@ module.exports = { iconURL: interaction.user.avatarURL() }) .setDescription( - `**Resumed**\n**[${queue.currentTrack.title}](${queue.currentTrack.url})**.` + `**${embedIcons.pauseResumed} Resumed track**\n**[${queue.currentTrack.title}](${queue.currentTrack.url})**.` ) .setThumbnail(queue.currentTrack.thumbnail) .setColor(embedColors.colorSuccess) diff --git a/commands/play.js b/commands/play.js index 7941988..6e02ab4 100644 --- a/commands/play.js +++ b/commands/play.js @@ -1,7 +1,12 @@ const { SlashCommandBuilder } = require('@discordjs/builders'); const { useMainPlayer, useQueue } = require('discord-player'); const { EmbedBuilder } = require('discord.js'); -const { embedColors, playerOptions, botInfo } = require('../config.json'); +const { + embedColors, + embedIcons, + playerOptions, + botInfo +} = require('../config.json'); module.exports = { data: new SlashCommandBuilder() @@ -22,7 +27,7 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - '**Failed**\nYou need to be in a voice channel to use this command.' + `**${embedIcons.warning} Oops!**\nYou need to be in a voice channel to use this command.` ) .setColor(embedColors.colorWarning) ] @@ -41,7 +46,7 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**No track found**\nNo results found for \`${query}\`.` + `**${embedIcons.warning} No track found**\nNo results found for \`${query}\`.\n\nIf you specified a URL, please make sure it is valid and public.` ) .setColor(embedColors.colorWarning) ] @@ -57,43 +62,91 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**Unsupported Source**\nThis audio source is a YouTube live stream, which is currently not a supported format.\n\n_If you think that this is incorrect, please submit a bug report in the bot [support server](${botInfo.supportServerInviteUrl})._` + `**${embedIcons.warning} Unsupported audio source**\nYouTube live streams are currently not supported. This is due to issues with extracting audio from the livestream.\n\n_If you think this message is incorrect, please submit a bug report in the **[support server](${botInfo.supportServerInviteUrl})**._` ) .setColor(embedColors.colorWarning) ] }); } - const { track } = await player.play( - interaction.member.voice.channel, - searchResult, - { - requestedBy: interaction.user, - nodeOptions: { - leaveOnEmpty: playerOptions.leaveOnEmpty ?? true, - leaveOnEmptyCooldown: - playerOptions.leaveOnEmptyCooldown ?? 60000, - leaveOnEnd: playerOptions.leaveOnEnd ?? true, - leaveOnEndCooldown: - playerOptions.leaveOnEndCooldown ?? 60000, - leaveOnStop: playerOptions.leaveOnStop ?? true, - leaveOnStopCooldown: - playerOptions.leaveOnStopCooldown ?? 60000, - maxSize: playerOptions.maxQueueSize ?? 1000, - maxHistorySize: playerOptions.maxHistorySize ?? 100, - volume: playerOptions.defaultVolume ?? 50 - } - } - ); + let track; - const queue = useQueue(interaction.guild.id); + try { + ({ track } = await player.play( + interaction.member.voice.channel, + searchResult, + { + requestedBy: interaction.user, + nodeOptions: { + leaveOnEmpty: playerOptions.leaveOnEmpty ?? true, + leaveOnEmptyCooldown: + playerOptions.leaveOnEmptyCooldown ?? 60000, + leaveOnEnd: playerOptions.leaveOnEnd ?? true, + leaveOnEndCooldown: + playerOptions.leaveOnEndCooldown ?? 60000, + leaveOnStop: playerOptions.leaveOnStop ?? true, + leaveOnStopCooldown: + playerOptions.leaveOnStopCooldown ?? 60000, + maxSize: playerOptions.maxQueueSize ?? 1000, + maxHistorySize: playerOptions.maxHistorySize ?? 100, + volume: playerOptions.defaultVolume ?? 50 + } + } + )); + } catch (error) { + if (error.message.includes('Sign in to confirm your age')) { + return await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setDescription( + `**${embedIcons.warning} Cannot retrieve audio for track**\nThis audio source is age restricted and requires login to access. Because of this I cannot retrieve the audio for the track.\n\n_If you think this message is incorrect, please submit a bug report in the **[support server](${botInfo.supportServerInviteUrl})**._` + ) + .setColor(embedColors.colorWarning) + ] + }); + } + + if ( + error.type === 'TypeError' && + (error.message.includes( + 'Cannot read properties of null (reading \'createStream\')' + ) || + error.message.includes( + 'Failed to fetch resources for ytdl streaming' + )) + ) { + return await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setDescription( + `**${embedIcons.error} Uh-oh... Failed to add track!**\nAfter finding a result, I was unable to retrieve audio for the track.\n\nYou can try to perform the command again.\n\n_If you think this message is incorrect, please submit a bug report in the **[support server](${botInfo.supportServerInviteUrl})**._` + ) + .setColor(embedColors.colorError) + ] + }); + } + + if (error.message === 'Cancelled') { + return await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setDescription( + `**${embedIcons.error} Uh-oh... Failed to add track!**\nSomething unexpected happened and the operation was cancelled.\n\nYou can try to perform the command again.\n\n_If you think this message is incorrect, please submit a bug report in the **[support server](${botInfo.supportServerInviteUrl})**._` + ) + .setColor(embedColors.colorError) + ] + }); + } + } + + let queue = useQueue(interaction.guild.id); if (!queue) { return await interaction.editReply({ embeds: [ new EmbedBuilder() .setDescription( - '**Failed**\nFailed to add track to queue. Please try again.' + `**${embedIcons.error} Uh-oh... Failed to add track!**\nThere was an issue adding this track to the queue.\n\nYou can try to perform the command again.\n\n_If this problem persists, please submit a bug report in the **[support server](${botInfo.supportServerInviteUrl})**._` ) .setColor(embedColors.colorError) ] @@ -119,7 +172,9 @@ module.exports = { iconURL: interaction.user.avatarURL() }) .setDescription( - `**Added playlist to queue**\n${durationFormat} **[${ + `**${ + embedIcons.success + } Added playlist to queue**\n${durationFormat} **[${ track.title }](${track.url})**\n\nAnd **${ searchResult.tracks.length - 1 @@ -140,7 +195,7 @@ module.exports = { iconURL: interaction.user.avatarURL() }) .setDescription( - `**Started playing**\n${durationFormat} **[${track.title}](${track.url})**` + `**${embedIcons.audioStartedPlaying} Started playing**\n${durationFormat} **[${track.title}](${track.url})**` ) .setThumbnail(track.thumbnail) .setColor(embedColors.colorSuccess) @@ -156,7 +211,7 @@ module.exports = { iconURL: interaction.user.avatarURL() }) .setDescription( - `**Added to queue**\n${durationFormat} **[${track.title}](${track.url})**` + `${embedIcons.success} **Added to queue**\n${durationFormat} **[${track.title}](${track.url})**` ) .setThumbnail(track.thumbnail) .setColor(embedColors.colorSuccess) diff --git a/commands/queue.js b/commands/queue.js index 19584f7..5c81d5c 100644 --- a/commands/queue.js +++ b/commands/queue.js @@ -1,7 +1,11 @@ const { SlashCommandBuilder } = require('@discordjs/builders'); const { useQueue } = require('discord-player'); const { EmbedBuilder } = require('discord.js'); -const { embedColors, progressBarOptions } = require('../config.json'); +const { + embedColors, + embedIcons, + progressBarOptions +} = require('../config.json'); module.exports = { data: new SlashCommandBuilder() @@ -20,19 +24,31 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - '**Failed**\nYou need to be in a voice channel to use this command.' + `**${embedIcons.warning} Oops!**\nYou need to be in a voice channel to use this command.` ) .setColor(embedColors.colorWarning) ] }); } + const pageIndex = (interaction.options.getNumber('page') || 1) - 1; const queue = useQueue(interaction.guild.id); let queueString = ''; if (!queue) { - queueString = - 'There are no tracks in the queue. Add tracks with `/play`!'; + if (pageIndex >= 1) { + return await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setDescription( + `**${embedIcons.warning} Oops!**\nPage \`${pageIndex + 1}\` is not a valid page number.\n\nThe queue is currently empty, first add some tracks with \`/play\`!` + ) + .setColor(embedColors.colorWarning) + ] + }); + } + + queueString = 'The queue is empty, add some tracks with `/play`!'; return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -40,7 +56,9 @@ module.exports = { name: interaction.guild.name, iconURL: interaction.guild.iconURL() }) - .setDescription(`**Queue**\n${queueString}`) + .setDescription( + `**${embedIcons.queue} Tracks in queue**\n${queueString}` + ) .setColor(embedColors.colorInfo) .setFooter({ text: 'Page 1 of 1' @@ -50,34 +68,33 @@ module.exports = { } const totalPages = Math.ceil(queue.tracks.data.length / 10) || 1; - const page = (interaction.options.getNumber('page') || 1) - 1; - if (page > totalPages - 1) { + if (pageIndex > totalPages - 1) { return await interaction.editReply({ embeds: [ new EmbedBuilder() .setDescription( - `**Error**\nInvalid page number. There are only a total of \`${totalPages}\` pages of tracks.` + `**${embedIcons.warning} Oops!**\nPage \`${pageIndex + 1}\` is not a valid page number.\n\nThere are only a total of \`${totalPages}\` pages in the queue.` ) - .setColor(embedColors.colorError) + .setColor(embedColors.colorWarning) ] }); } if (queue.tracks.data.length === 0) { - queueString = 'There are no tracks in the queue.'; + queueString = 'The queue is empty, add some tracks with `/play`!'; } else { queueString = queue.tracks.data - .slice(page * 10, page * 10 + 10) + .slice(pageIndex * 10, pageIndex * 10 + 10) .map((track, index) => { let durationFormat = track.raw.duration === 0 || track.duration === '0:00' ? '' : `\`${track.duration}\``; - return `**${page * 10 + index + 1}.** ${durationFormat} [${ + return `**${pageIndex * 10 + index + 1}.** ${durationFormat} **[${ track.title - }](${track.url})`; + }](${track.url})**`; }) .join('\n'); } @@ -94,9 +111,11 @@ module.exports = { }kbps)`, iconURL: interaction.guild.iconURL() }) - .setDescription(`**Queue**\n${queueString}`) + .setDescription( + `**${embedIcons.queue} Tracks in queue**\n${queueString}` + ) .setFooter({ - text: `Page ${page + 1} of ${totalPages}` + text: `Page ${pageIndex + 1} of ${totalPages}` }) .setColor(embedColors.colorInfo) ] @@ -118,7 +137,7 @@ module.exports = { currentTrack.raw.duration === 0 || currentTrack.duration === '0:00' ) { - bar = 'No duration available.'; + bar = '_No duration available._'; } return await interaction.editReply({ @@ -131,17 +150,17 @@ module.exports = { iconURL: interaction.guild.iconURL() }) .setDescription( - '**Currently playing**\n' + + `**${embedIcons.audioPlaying} Now playing**\n` + (currentTrack ? `**[${currentTrack.title}](${currentTrack.url})**` : 'None') + `\nRequested by: <@${currentTrack.requestedBy.id}>` + `\n ${bar}` + - `\n\n**Queue**\n${queueString}` + `\n\n**${embedIcons.queue} Tracks in queue**\n${queueString}` ) .setThumbnail(queue.currentTrack.thumbnail) .setFooter({ - text: `Page ${page + 1} of ${totalPages}` + text: `Page ${pageIndex + 1} of ${totalPages}` }) .setColor(embedColors.colorInfo) ] diff --git a/commands/remove.js b/commands/remove.js index d3efe45..8303e34 100644 --- a/commands/remove.js +++ b/commands/remove.js @@ -1,7 +1,7 @@ const { SlashCommandBuilder } = require('@discordjs/builders'); const { useQueue } = require('discord-player'); const { EmbedBuilder } = require('discord.js'); -const { embedColors } = require('../config.json'); +const { embedColors, embedIcons } = require('../config.json'); module.exports = { data: new SlashCommandBuilder() @@ -21,7 +21,7 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - '**Failed**\nYou need to be in a voice channel to use this command.' + `**${embedIcons.warning} Oops!**\nYou need to be in a voice channel to use this command.` ) .setColor(embedColors.colorWarning) ] @@ -35,7 +35,7 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - '**Failed**\nThere are no tracks in the queue. Add tracks with `/play`!' + `**${embedIcons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with \`/play\`!` ) .setColor(embedColors.colorWarning) ] @@ -49,15 +49,19 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**Error**\nThere are \`${queue.tracks.data.length}\` tracks in the queue. You cannot remove track number \`${removeTrackNumber}\`.` + `**${embedIcons.warning} Oops!**\nTrack \`${removeTrackNumber}\` is not a valid track number. There are a total of\`${queue.tracks.data.length}\` tracks in the queue.\n\nView tracks added to the queue with \`/queue\`.` ) - .setColor(embedColors.colorError) + .setColor(embedColors.colorWarning) ] }); } // Remove specified track number from queue const removedTrack = queue.node.remove(removeTrackNumber - 1); + let durationFormat = + removedTrack.raw.duration === 0 || removedTrack.duration === '0:00' + ? '' + : `\`${removedTrack.duration}\``; return await interaction.editReply({ embeds: [ @@ -67,7 +71,7 @@ module.exports = { iconURL: interaction.user.avatarURL() }) .setDescription( - `**Removed**\n**[${removedTrack.title}](${removedTrack.url})**.` + `**${embedIcons.success} Removed track**\n${durationFormat} **[${removedTrack.title}](${removedTrack.url})**.` ) .setThumbnail(removedTrack.thumbnail) .setColor(embedColors.colorSuccess) diff --git a/commands/skip.js b/commands/skip.js index 9e74ffd..30d5fae 100644 --- a/commands/skip.js +++ b/commands/skip.js @@ -1,12 +1,12 @@ const { SlashCommandBuilder } = require('@discordjs/builders'); const { useQueue } = require('discord-player'); const { EmbedBuilder } = require('discord.js'); -const { embedColors } = require('../config.json'); +const { embedColors, embedIcons } = require('../config.json'); module.exports = { data: new SlashCommandBuilder() .setName('skip') - .setDescription('Skip the current track.') + .setDescription('Skip current or specified track.') .setDMPermission(false) .addNumberOption((option) => option @@ -20,7 +20,7 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - '**Failed**\nYou need to be in a voice channel to use this command.' + `**${embedIcons.warning} Oops!**\nYou need to be in a voice channel to use this command.` ) .setColor(embedColors.colorWarning) ] @@ -34,7 +34,7 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - '**Failed**\nThere are no tracks in the queue. Add tracks with `/play`!' + `**${embedIcons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with \`/play\`!` ) .setColor(embedColors.colorWarning) ] @@ -49,9 +49,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**Error**\nThere are \`${queue.tracks.data.length}\` tracks in the queue. You cannot skip to track number \`${skipToTrack}\`.` + `**${embedIcons.warning} Oops!**\nThere are only \`${queue.tracks.data.length}\` tracks in the queue. You cannot skip to track \`${skipToTrack}\`.\n\nView tracks added to the queue with \`/queue\`.` ) - .setColor(embedColors.colorError) + .setColor(embedColors.colorWarning) ] }); } else { @@ -71,7 +71,7 @@ module.exports = { iconURL: interaction.user.avatarURL() }) .setDescription( - `**Skipped track**\n${durationFormat} **[${skippedTrack.title}](${skippedTrack.url})**.` + `**${embedIcons.skipped} Skipped track**\n${durationFormat} **[${skippedTrack.title}](${skippedTrack.url})**.` ) .setThumbnail(skippedTrack.thumbnail) .setColor(embedColors.colorSuccess) @@ -84,7 +84,7 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - '**Failed**\nThere are no tracks in the queue and nothing currently playing.' + `**${embedIcons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with \`/play\`!` ) .setColor(embedColors.colorWarning) ] @@ -107,7 +107,7 @@ module.exports = { iconURL: interaction.user.avatarURL() }) .setDescription( - `**Skipped track**\n${durationFormat} **[${skippedTrack.title}](${skippedTrack.url})**.` + `**${embedIcons.skipped} Skipped track**\n${durationFormat} **[${skippedTrack.title}](${skippedTrack.url})**.` ) .setThumbnail(skippedTrack.thumbnail) .setColor(embedColors.colorSuccess) diff --git a/commands/volume.js b/commands/volume.js index ad70f95..dfea041 100644 --- a/commands/volume.js +++ b/commands/volume.js @@ -1,7 +1,7 @@ const { SlashCommandBuilder } = require('@discordjs/builders'); const { useQueue } = require('discord-player'); const { EmbedBuilder } = require('discord.js'); -const { embedColors } = require('../config.json'); +const { embedColors, embedIcons } = require('../config.json'); module.exports = { data: new SlashCommandBuilder() @@ -12,7 +12,7 @@ module.exports = { option .setName('percentage') .setDescription('Set volume percentage from 1% to 100%.') - .setMinValue(1) + .setMinValue(0) .setMaxValue(100) ), run: async ({ interaction }) => { @@ -21,7 +21,7 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - '**Failed**\nYou need to be in a voice channel to use this command.' + `**${embedIcons.warning} Oops!**\nYou need to be in a voice channel to use this command.` ) .setColor(embedColors.colorWarning) ] @@ -35,7 +35,7 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - '**Failed**\nThere are no tracks playing or in the queue. Add tracks with `/play`!' + `**${embedIcons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with \`/play\`!` ) .setColor(embedColors.colorWarning) ] @@ -44,29 +44,45 @@ module.exports = { const volume = interaction.options.getNumber('percentage'); - if (!volume) { + if (!volume && volume !== 0) { return await interaction.editReply({ embeds: [ new EmbedBuilder() .setDescription( - `**Volume**\nThe playback volume is currently set at \`${queue.node.volume}%\`.` + `**${embedIcons.volume} Playback volume**\nThe playback volume is currently set to \`${queue.node.volume}%\`.` ) .setColor(embedColors.colorInfo) ] }); - } else if (volume > 100 || volume < 1) { + } else if (volume > 100 || volume < 0) { return await interaction.editReply({ embeds: [ new EmbedBuilder() .setDescription( - '**Error**\nYou need to pick a number between `1` and `100`.' + `**${embedIcons.warning} Oops!**\nYou cannot set the volume to \`${volume}\`, please pick a value betwen \`1\`% and \`100\`%.` ) - .setColor(embedColors.colorError) + .setColor(embedColors.colorWarning) ] }); } else { queue.node.setVolume(volume); + if (volume === 0) { + return await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setAuthor({ + name: interaction.user.username, + iconURL: interaction.user.avatarURL() + }) + .setDescription( + `**${embedIcons.volumeChanged} Audio muted**\nPlayback audio has been muted, because volume was set to \`${volume}%\`.` + ) + .setColor(embedColors.colorSuccess) + ] + }); + } + return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -75,7 +91,7 @@ module.exports = { iconURL: interaction.user.avatarURL() }) .setDescription( - `**Volume changed**\nPlayback volume has been set to \`${volume}%\`.` + `**${embedIcons.volumeChanged} Volume changed**\nPlayback volume has been changed to \`${volume}%\`.` ) .setColor(embedColors.colorSuccess) ] diff --git a/config.json.example b/config.json.example index 76b608b..e935119 100644 --- a/config.json.example +++ b/config.json.example @@ -28,7 +28,7 @@ "maxHistorySize": 100 }, "progressBarOptions": { - "length": 12, + "length": 14, "timecodes": false, "separator": "┃", "indicator": "🔘", @@ -36,10 +36,32 @@ "rightChar": "▬" }, "embedIcons": { + "logo": "🤖", "beta": "`beta`", + "new": "`new`", "rule": "📒", "support": "❓", - "bot": "🤖" + "bot": "🤖", + "audioPlaying": "🎶", + "audioStartedPlaying": "🎶", + "success": "✅", + "error": "⚠️", + "warning": "⚠️", + "disable": "🚫", + "enable": "✅", + "disabled": "✅", + "enabled": "✅", + "nextTrack": "⏭️", + "previousTrack": "⏮️", + "pauseResumeTrack": "⏯️", + "shuffleQueue": "🔀", + "skipped": "⏭️", + "back": "⏮️", + "pauseResumed": "⏯️", + "shuffled": "🔀", + "volume": "🔊", + "volumeChanged": "🔊", + "queue": "🎶" }, "filterThreadAmount": "2", "filterList": [ diff --git a/index.js b/index.js index 7f50aa7..c200ad0 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ const logger = require('./services/logger.js'); const { EmbedBuilder } = require('discord.js'); const { Player, onBeforeCreateStream } = require('discord-player'); const { stream } = require('yt-stream'); -const { embedColors, botInfo } = require('./config.json'); +const { embedColors, embedIcons, botInfo } = require('./config.json'); require('dotenv').config(); // Setup required permissions for the bot to work @@ -154,9 +154,6 @@ client.on('interactionCreate', async (interaction) => { `(${interaction.guild.memberCount}) ${interaction.guild.name}> Command '${interaction}' took ${executionTime} ms to execute.` ); - // todo: using interaction.editReply() might lead to "unknown interaction" error - // it might already have been replied to or deferred - // solution might be to use interaction.followUp() instead or send a message to the channel? return await interaction.followUp({ embeds: [ new EmbedBuilder() @@ -179,14 +176,11 @@ client.on('interactionCreate', async (interaction) => { `(${interaction.guild.memberCount}) ${interaction.guild.name}> Command '${interaction}' failed to execute.` ); - // todo: using interaction.editReply() might lead to "unknown interaction" error - // it might already have been replied to or deferred - // solution might be to use interaction.followUp() instead or send a message to the channel? await interaction.followUp({ embeds: [ new EmbedBuilder() .setDescription( - `**Unexpected Error**\nThere was an error while executing this command! Please try again.\n\n_If this issue persists, please submit a bug report in the bot [support server](${botInfo.supportServerInviteUrl})._` + `**${embedIcons.error} Uh-oh... _Something_ went wrong!**\nThere was an unexpected error while trying to execute this command.\n\nYou can try to perform the command again.\n\n_If this problem persists, please submit a bug report in the **[support server](${botInfo.supportServerInviteUrl})**._` ) .setColor(embedColors.colorError) ] diff --git a/system-commands/guilds.js b/system-commands/guilds.js index 97ffc22..77ea5a5 100644 --- a/system-commands/guilds.js +++ b/system-commands/guilds.js @@ -1,6 +1,10 @@ const { SlashCommandBuilder } = require('@discordjs/builders'); const { EmbedBuilder } = require('discord.js'); -const { embedColors, systemServerGuildIds } = require('../config.json'); +const { + embedColors, + embedIcons, + systemServerGuildIds +} = require('../config.json'); module.exports = { data: new SlashCommandBuilder() @@ -13,9 +17,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**No permission**\nThe command \`${interaction.commandName}\` cannot be executed in this server.` + `**${embedIcons.warning} Oops!**\nNo permission to execute this command.\n\nThe command \`${interaction.commandName}\` cannot be executed in this server.` ) - .setColor(embedColors.colorError) + .setColor(embedColors.colorWarning) ] }); } @@ -27,11 +31,16 @@ module.exports = { memberCount: guild.memberCount }; }) + .slice(0, 50) .sort((a, b) => b.memberCount - a.memberCount) - .map((guild) => `\`${guild.name} (#${guild.memberCount})\``) - .join(', '); + .map((guild, index) => `${index + 1}. \`${guild.name} (#${guild.memberCount})\``) + .join('\n'); - let embedDescription = `**Guilds (${client.guilds.cache.size} total)**\n${guildsList}`; + let embedDescription = `**${embedIcons.bot} ${ + client.guilds.cache.size < 50 + ? 'Guilds' + : `Top ${client.guilds.cache.size} guilds` + } by member count (${client.guilds.cache.size} total)**\n${guildsList}`; if (embedDescription.length >= 4000) { embedDescription = `${embedDescription.slice(0, 3996)}...`; diff --git a/system-commands/status.js b/system-commands/status.js index c5ba1b9..4a0f742 100644 --- a/system-commands/status.js +++ b/system-commands/status.js @@ -1,7 +1,11 @@ const { SlashCommandBuilder } = require('@discordjs/builders'); const { EmbedBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); -const { embedColors, systemServerGuildIds } = require('../config.json'); +const { + embedColors, + embedIcons, + systemServerGuildIds +} = require('../config.json'); const osu = require('node-os-utils'); const packageJson = require('../package.json'); @@ -16,9 +20,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**No permission**\nThe command \`${interaction.commandName}\` cannot be executed in this server.` + `**${embedIcons.warning} Oops!**\nNo permission to execute this command.\n\nThe command \`${interaction.commandName}\` cannot be executed in this server.` ) - .setColor(embedColors.colorError) + .setColor(embedColors.colorWarning) ] }); } @@ -56,7 +60,7 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - '**System and bot status**\n' + + `**${embedIcons.bot} System and bot status**\n` + `Uptime: \`${uptimeString}\`\n` + `Platform: \`${platform}\`\n` + `CPU cores: \`${cpuCores}\`\n` +